单试图控制器——6种基本触摸手势

定义部分

   //1.轻拍手势

    //    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changViewBackgroundColor:)];

    //    tapGesture.numberOfTapsRequired = 2;//需要点击两次触法

    //    tapGesture.numberOfTouchesRequired = 2;//需要两根手指点击触法

    //    [aView addGestureRecognizer:tapGesture];

    

    //2.长按手势

    //    UILongPressGestureRecognizer *longPerss = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(changViewBackgroundColor:)];

    //    longPerss.minimumPressDuration = 2.0;//设置长按触发的最短时间

    //    [aView addGestureRecognizer:longPerss];

    //长按手势在结束的时候会再次调用该方法,设置state值设为只在开始触法时调用该方法。

    //    if (tap.state == UIGestureRecognizerStateBegan)

    

    //3.轻扫手势

    //    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changViewBackgroundColor:)];

    //    swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;//设置触法的方向为从下到上,初始为从左至右

    //    [aView addGestureRecognizer:swipeGesture];

    

    //4.拖动手势

//    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];

//    [aView addGestureRecognizer:panGesture];

    

    //5.捏合手势

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

//    [aView addGestureRecognizer:pinchGesture];

    

    //6.旋转手势

    UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];

    [aView addGestureRecognizer:rotationGesture];

实现部分

//- (void)changViewBackgroundColor:(UISwipeGestureRecognizer *)tap

//{

//    UIView *aView = tap.view;

//    aView.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];

//    NSLog(@"tap");

//}

------------------------------------------------------------------------我是分割线---------------------------------------------------------------------

//- (void)panAction:(UIPanGestureRecognizer *)panGesture

//{

//    //获得的偏移量是基于手指触摸初始点的偏移量

//    CGPoint offsetPoint = [panGesture translationInView:panGesture.view];

//    NSLog(@"offset point = %@",NSStringFromCGPoint(offsetPoint));

//    //更改Viewtransform

//    panGesture.view.transform = CGAffineTransformMakeTranslation(offsetPoint.x, offsetPoint.y);

//}

------------------------------------------------------------------------我是分割线---------------------------------------------------------------------

//- (void)pinchAction:(UIPinchGestureRecognizer *)pinch

//{

//    NSLog(@"scale = %f",pinch.scale);

//    //View缩放

//    pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);

//}

------------------------------------------------------------------------我是分割线---------------------------------------------------------------------

- (void)rotationAction:(UIRotationGestureRecognizer *)rotation

{

    NSLog(@"rotation = %f",rotation.rotation);

    //View旋转

    rotation.view.transform = CGAffineTransformMakeRotation(rotation.rotation);

}


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值