iOS开发从入门到精通--UIGesture手势基础
2016-07-27 09:23
549 查看
UIGesture手势基础
#import <UIKit/UIKit.h> @interface ViewController : UIViewController{ //定义一个视图对象 UIImageView * _imageView; } @end
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //加载图像对象,从本地加载到内存 UIImage * image =[UIImage imageNamed:@"17_2.png"]; //创建图像视图 _imageView = [[UIImageView alloc]init]; //将图像视图的图像赋值 _imageView.image = image; _imageView.frame =CGRectMake(50, 80, 200, 300); [self.view addSubview:_imageView]; //开启交互事件响应开关 //YES:可以响应交互事件 //NO:不能接受响应事件,默认值为NO; _imageView.userInteractionEnabled=YES; //创建一个点击手势对象 //UITapGestureRecognizer:点击手势类 //功能:识别点击手势事件 //p1:响应事件的拥有者对象,self表示当前视图控制器 //p2:响应事件的函数 UITapGestureRecognizer * tapOneGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOneAct:)]; //表示手势识别事件的事件类型:几次点击时触发 //默认值为1 tapOneGes.numberOfTapsRequired=1; // tapOneGes.numberOfTapsRequired=2; //表示几个手指点击时触发此事件函数 //默认值为1 tapOneGes.numberOfTouchesRequired=1; //将点击事件添加到视图中,视图即可响应事件 [_imageView addGestureRecognizer:tapOneGes]; UITapGestureRecognizer * tapTwoGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwoGes:)]; tapTwoGes.numberOfTapsRequired=2; tapTwoGes.numberOfTouchesRequired=1; [_imageView addGestureRecognizer:tapTwoGes]; //当单击操作遇到双击操作时,单击操作失效 [tapOneGes requireGestureRecognizerToFail:tapTwoGes]; } //事件响应函数,单击操作 //参数手势点击事件对象 -(void) tapOneAct:(UITapGestureRecognizer*)tap{ NSLog(@"单击操作!"); //获取手势监控的视图对象 UIImageView * imageView = (UIImageView*)tap.view; //开始动画过程 [UIView beginAnimations:nil context:nil]; //设置动画过度时间 [UIView setAnimationDuration:2]; imageView.frame=CGRectMake(0, 0, 320, 568); //结束动画过程 [UIView commitAnimations]; } //双击操作 -(void)tapTwoGes:(UITapGestureRecognizer*)tap{ NSLog(@"双击操作"); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; _imageView.frame =CGRectMake(50, 80, 200, 300); [UIView commitAnimations]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 神奇的Fastcgi_Finish_Request
- CodeForces 289B Polo the Penguin and Matrix
- jsp Request获取url信息的各种方法比较
- 版本库重新定位时svn uuid不一致问题
- CodeForces 289A Polo the Penguin and Segments
- Rookey.Frame之实体FluentValidation验证
- iOS开发从入门到精通--UITouch 触摸事件处理
- RabbitMQ是一个由erlang开发的基于AMQP(Advanced Message Queue )协议的开源实现。
- Visual Studio中的Build Event
- Guess Number Higher or Lower II
- 优秀设计师必须知道哪些优秀的UI设计原则
- Guess Number
- private static final long serialVersionUID = 1L 干什么的?
- 使用AmazeUI做的一个表单案例(验证)
- POJ-2524 Ubiquitous Religions(并查集)
- Top K Frequent Elements
- csu 1555 Inversion Sequence 线段树反求逆序数
- duilib基本框架
- UE4技巧
- form表单提交前通过jq验证(ajax特别说明,return true失效)