我的iOS学习历程 - 手势

我们在手机上可以用很多手势来触发不同的操作,今天就是学习怎样去添加手势

添加手势步骤
  1. 初始化手势 添加手势触发调用的方法
  2. 把手势添加到视图上
  3. 释放手势
    1.长按
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
// 设置长按时间
    longPress.minimumPressDuration = 2.0;
    [imageView addGestureRecognizer:longPress];
    [longPress release];

2.旋转

UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAciton:)];
    [imageView addGestureRecognizer:rotation];
    [rotation release];

3.捏合

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAciton:)];
    [imageView addGestureRecognizer:pinch];
    [pinch release];

4.平移

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
    [imageView addGestureRecognizer:pan];
    [pan release];

5.轻扫

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
    swipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [imageView addGestureRecognizer:swipe];
    [swipe release];

6.边缘扫

UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgePanAction:)];
// 设置下从哪个边缘开始扫
    screenEdgePan.edges = UIRectEdgeRight;
    [imageView addGestureRecognizer:screenEdgePan];
    [screenEdgePan release];

每个手势添加的方法可以在下面自己写例如
实现轻拍方法:

- (void)tapAction:(UITapGestureRecognizer *)tap
{
       NSLog(@"你拍我了, 很轻");
       UIImageView *imageView = (UIImageView *)tap.view;
       imageView.image = [UIImage imageNamed:@"Highlighted"];

}

这就是我们的手势学习了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值