iOS 旋转手势
2016-03-09 15:53
375 查看
iOS的手势功能很强大,大家都知道。但是如何使用了?
这里 我们简单的以一个UILabel测试一下旋转
下节 我们将简单讲一讲 拖动手势 有兴趣可以看看:http://blog.csdn.net/lwjok2007/article/details/50836883
使用Xcode 创建一个工程 起名testRotation
我们在默认生成的ViewController中写代码
首先我们创建两个变量
在viewDidLoad 中创建
在创建方法实现接收旋转事件后的操作
好了 运行项目试试 看能不能旋转
源代码我会上传到群空间,大家有兴趣可以去下载
源代码名称:【60309旋转手势Rotation.zip】
好了,大家可以去试试
苹果开发群 :414319235 欢迎加入,共同学习
这里 我们简单的以一个UILabel测试一下旋转
下节 我们将简单讲一讲 拖动手势 有兴趣可以看看:http://blog.csdn.net/lwjok2007/article/details/50836883
使用Xcode 创建一个工程 起名testRotation
我们在默认生成的ViewController中写代码
首先我们创建两个变量
UILabel *testLable; //label用来测试旋转 CGFloat testLabelRotation; //label的旋转角度
在viewDidLoad 中创建
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //创建lable 添加到View testLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 36)]; testLable.center=CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0); testLable.textAlignment=NSTextAlignmentCenter; testLable.text = @"金轱辘棒棒辘轱金"; [testLable sizeToFit]; [self.view addSubview:testLable]; //创建UIRotationGestureRecognizer 用来实现旋转手势 UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAct:)]; [self.view addGestureRecognizer:rotationGR]; }
在创建方法实现接收旋转事件后的操作
//当旋转时执行此方法 - (void)rotationAct:(UIRotationGestureRecognizer *)sender{ //根据传回的旋转角度修改lable的当前角度 testLable.transform = CGAffineTransformMakeRotation(testLabelRotation+sender.rotation); //当旋转结束后更新lable的角度,以备下次使用 if (sender.state == UIGestureRecognizerStateEnded) { testLabelRotation += sender.rotation; } }
好了 运行项目试试 看能不能旋转
源代码我会上传到群空间,大家有兴趣可以去下载
源代码名称:【60309旋转手势Rotation.zip】
好了,大家可以去试试
苹果开发群 :414319235 欢迎加入,共同学习
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- C#实现字体旋转的方法
- 基于jQuery实现的旋转彩圈实例
- C++实现一维向量旋转算法
- 使用JavaScript实现旋转的彩圈特效
- jQuery平滑旋转幻灯片特效代码分享
- jquery实现可旋转可拖拽的文字效果代码
- jQuery+CSS3实现3D立方体旋转效果
- C#中图片旋转和翻转(RotateFlipType)用法分析
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用中UISearchDisplayController搜索效果的用法
- IOS开发环境windows化攻略