当前位置:首页 > ios开发中的6种手势识别的实现
学IT技能上我学院网woxueyuan.com
UISwipeGestureRecognizer *swipe = sender; if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) { //向左轻扫 } if (swipe.direction == UISwipeGestureRecognizerDirectionRight) { //向右轻扫 } } 4、捏合手势(PinchGestureRecognizer)
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)]; [self.view addGestureRecognizer:pinchGesture]; ////捏合手势触发方法 -(void) pinchGesture:(id)sender Unity3D|Cocos|php|HTML5|Java|ios|Android|C#|AS3|PS|UI|3Dmax|Python|MySQL|VR|AR
学IT技能上我学院网woxueyuan.com
{ UIPinchGestureRecognizer *gesture = sender; //手势改变时 if (gesture.state == UIGestureRecognizerStateChanged) { //捏合手势中scale属性记录的缩放比例 _imageView.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale); } //结束后恢复 if(gesture.state==UIGestureRecognizerStateEnded) { [UIView animateWithDuration:0.5 animations:^{ _imageView.transform = CGAffineTransformIdentity;//取消一切形变 }]; } } Unity3D|Cocos|php|HTML5|Java|ios|Android|C#|AS3|PS|UI|3Dmax|Python|MySQL|VR|AR
学IT技能上我学院网woxueyuan.com
5、拖动手势(PanGestureRecognizer)
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)]; [self.view addGestureRecognizer:panGesture]; //拖动手势触发方法 -(void) panGesture:(id)sender { UIPanGestureRecognizer *panGesture = sender; CGPoint movePoint = [panGesture translationInView:self.view]; //your code } 6、旋转手势(RotationGestureRecognizer)
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)]; [self.view addGestureRecognizer:rotationGesture]; //旋转手势触发方法 Unity3D|Cocos|php|HTML5|Java|ios|Android|C#|AS3|PS|UI|3Dmax|Python|MySQL|VR|AR 学IT技能上我学院网woxueyuan.com
-(void)rotationGesture:(id)sender { UIRotationGestureRecognizer *gesture = sender; if (gesture.state==UIGestureRecognizerStateChanged) { _imageView.transform=CGAffineTransformMakeRotation(gesture.rotation); } if(gesture.state==UIGestureRecognizerStateEnded) { [UIView animateWithDuration:1 animations:^{ _imageView.transform=CGAffineTransformIdentity;//取消形变 }]; } } 关注我学院微信公众号(woxueyuan_)com),就可以随时随地观看你喜欢的视频教程,我学院教程全面覆盖PC、手机及MAC端。只要你想学,随时随地都可以。
Unity3D|Cocos|php|HTML5|Java|ios|Android|C#|AS3|PS|UI|3Dmax|Python|MySQL|VR|AR
共分享92篇相关文档