捏合手势

- (void)viewDidLoad

{

    [super viewDidLoad];

    _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 320, 30)];

    _label.textAlignment = NSTextAlignmentCenter;

    _label.backgroundColor = [UIColor whiteColor];

    _label.textColor = [UIColor redColor];

    _label.text = @"捏合手势";

    

    [self.view addSubview:_label];

    

    UIView *gestureView = [[UIView alloc] initWithFrame:CGRectMake(0, 60, 320, 410)];

    gestureView.backgroundColor = [UIColor greenColor];

    

    [self.view addSubview:gestureView];

    

    //------------------------捏合手势------------------------

    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1Action:)];

    //连续点击的数量

    tap1.numberOfTapsRequired = 1;

    //设置手指点击的数量

    //    tap1.numberOfTapsRequired = 2;

    [gestureView addGestureRecognizer:tap1];

    [tap1 release];

    

    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2Action:)];

    //连续点击的数量

    tap2.numberOfTapsRequired = 2;

    [gestureView addGestureRecognizer:tap2];

    [tap2 release];

    

    //假如tap1tap2两个手势都触发,则取消tap1手势

    [tap1 requireGestureRecognizerToFail:tap2];

    

    //--------------------轻扫手势-------------------------

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];

    //设置轻扫的方向

    swipe.direction = UISwipeGestureRecognizerDirectionRight;

    [gestureView addGestureRecognizer:swipe];

    [swipe release];

    

    //--------------------移动手势----------------------------

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAtion:)];

    [gestureView addGestureRecognizer:pan];

    [pan release];

    

    //-------------------长按手势--------------------------------

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longAction:)];

    [gestureView addGestureRecognizer:longPress];

    [longPress release];

    

    //------------------旋转手势----------------------------------

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAtion:)];

    [gestureView addGestureRecognizer:rotation];

    [rotation release];

    

    //-----------------捏合手势----------------------------

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

    [gestureView addGestureRecognizer:pinch];

    [pinch release];


    

    

    

}


- (void)tap1Action:(UITapGestureRecognizer *)tap

{

    NSLog(@"单机");

    _label.text = @"单机";

}


- (void)tap2Action:(UITapGestureRecognizer *)tap

{

    NSLog(@"双机");

    _label.text = @"双机";

}


- (void)swipeAction:(UITapGestureRecognizer *)swip

{

    NSLog(@"轻扫");

    _label.text = @"轻扫";

}


- (void)panAtion:(UITapGestureRecognizer *)pan

{

    NSLog(@"移动");

    _label.text = @"移动";

}

- (void)longAction:(UITapGestureRecognizer *)pan

{

    NSLog(@"长按");

    _label.text = @"长按";

}

- (void)rotationAtion:(UITapGestureRecognizer *)pan

{

    NSLog(@"旋转");

    _label.text = @"旋转";

}

- (void)pinchAction:(UITapGestureRecognizer *)pan

{

    NSLog(@"捏合");

    _label.text = @"捏合";

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值