ios简单手势操作2
2014-01-03 17:40
357 查看
iOS中简单的手势操作:长按、捏合、移动和旋转
新建一个single view工程
ViewController.h文件
ViewController.m文件
新建一个single view工程
ViewController.h文件
#import <UIKit/UIKit.h> @interface ViewController : UIViewController { UIImageView *_imgView; float _rotation; } @end
ViewController.m文件
#import "ViewController.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 160, 100, 150)]; _imgView.image = [UIImage imageNamed:@"10_0.jpg"]; [self.view addSubview:_imgView]; [_imgView release]; _imgView.userInteractionEnabled = YES; //长按 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; // longPress.minimumPressDuration = 0;//效果等于轻触 longPress.minimumPressDuration = 2;//最少按两秒才会触发事件 // [_imgView addGestureRecognizer:longPress]; [longPress release]; //捏合 UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchPress:)]; [_imgView addGestureRecognizer:pinch]; [pinch release]; //移动 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; [_imgView addGestureRecognizer:pan]; [pan release]; //旋转 UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)]; [_imgView addGestureRecognizer:rotation]; [rotation release]; } - (void)rotation:(UIRotationGestureRecognizer *)rotation { _imgView.transform = CGAffineTransformMakeRotation(_rotation + rotation.rotation); if (rotation.state == UIGestureRecognizerStateCancelled) { _rotation = rotation.rotation+_rotation; } NSLog(@"%f", _rotation); } - (void)pan:(UIPanGestureRecognizer *)pan { CGPoint point = [pan translationInView:self.view]; _imgView.center = CGPointMake(_imgView.center.x+point.x, _imgView.center.y+point.y); [pan setTranslation:CGPointZero inView:self.view];//重置参考位置 } - (void)pinchPress:(UIPinchGestureRecognizer *)pinch { CGSize _imgSize = CGSizeMake(100, 150); float scale = pinch.scale; _imgView.bounds = CGRectMake(0, 0, _imgSize.width*scale, _imgSize.height*scale); //判断手势状态 if (pinch.state == UIGestureRecognizerStateCancelled) { _imgSize = _imgView.bounds.size; } if (_imgSize.height <= 75) { _imgSize.height = 75; _imgSize.width = 50; } } - (void)longPress:(UILongPressGestureRecognizer *)lp { NSLog(@"长按"); } @end
相关文章推荐
- ios简单手势操作-模态视图
- ios的手势操作之UIGestureRecognizer浅析
- IOS SWIFT 简单操作文件
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
- IOS各种手势操作实例
- 手势操作知识大餐 ——iOS
- iOS手势操作UIGestureRecognizer
- iOS----手势操作
- IOS学习之 手势操作
- iOS手势类的简单使用
- iOS-自定义手势操作
- ios的手势操作之UIGestureRecognizer浅析
- IOS 文件读写操作详解及简单实例
- ios的手势操作之UIGestureRecognizer浅析
- iOS自定义弹出视图,以及简单的手势讲解
- IOS 手势操作详解及实例总结篇
- 简单测试,iOS,webview的手势禁用
- IOS高级教程3:UITapGestureRecognizer手势识别的简单使用到精通
- IOS控件 动画操作 与 CALayer 简单操作
- 使用微软Kinect进行手势识别操作的一个简单范例(2)(WPF-C#)