我的iOS学习历程 - 手势
2015-11-21 10:29
441 查看
我们在手机上可以用很多手势来触发不同的操作,今天就是学习怎样去添加手势
添加手势步骤
初始化手势 添加手势触发调用的方法把手势添加到视图上
释放手势
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"]; }
这就是我们的手势学习了
相关文章推荐
- 我的iOS学习历程 - 手势
- ios审核加急服务
- iOS开发中CALayer使用的基本教程
- iOS 开发导航栏使用系统自定义属性基本4条
- iOS中 target/action 设计模式
- 【iOS】PLA 3.3.12
- [黑马IOS自学第八篇]C语言文件操作,通讯录实现,代码
- iOS开源库
- 百度地图demo-不显示地图
- 如何跨控制器跳转 iOS 返回到上上级控制器
- ios小功能
- IOS学习之视图
- Phonegap之ios对iPhone6和Plus的闪屏适配 -- xmTan
- iOS 8 Auto Layout界面自动布局系列3-使用代码添加布局约束
- IOS - LocationManager定位国内偏移,火星坐标(GCJ-02)解决方法
- iOS_程序执行顺序
- ios tableview下拉头部图片变大
- 蜂窝教育iOS培训:让学员月薪万元入职
- iOS ViewController之间传值方法三(利用NSNotification)
- 清除IOS项目中无用的图片资源