IOS学习之——Gesture手势基础
2016-04-21 14:04
399 查看
// // MyViewController.m // 网络NSUIrConnect // // #import "MyViewController.h" @interface MyViewController () @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor]; //添加图片 UIImage *imge=[UIImage imageNamed:@"welcome1"]; UIImageView *iv=[[UIImageView alloc]initWithImage:imge]; iv.frame=CGRectMake(50, 80, 200, 300); [self.view addSubview:iv]; //开启交互事件响应 iv.userInteractionEnabled=YES; //UITapGestureRecognizer点击手势类 //功能:识别点击手势事件 UITapGestureRecognizer *tapOne=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOneAct:)]; //表示收拾识别事件的事件类型:几次点击事件 //默认值是1 tapOne.numberOfTapsRequired=1; //表示几个手指触发此事件函数 //默认值是1 tapOne.numberOfTouchesRequired=1; //将点击事件添加到视图中,视图即可响应事件 [iv addGestureRecognizer:tapOne]; UITapGestureRecognizer *tapTwo=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTwoAct:)]; //双击事件 tapTwo.numberOfTapsRequired=2; //表示几个手指触发此事件函数 tapTwo.numberOfTouchesRequired=1; //将点击事件添加到视图中,视图即可响应事件 [iv addGestureRecognizer:tapTwo]; //点击双击时,单击失效 [tapTwo requireGestureRecognizerToFail:tapOne]; } -(void)tapTwoAct:(UITapGestureRecognizer *) sender{ NSLog(@"双击事件……"); //获取点击的View UIImageView *iv=(UIImageView*)sender.view; //动画开启 [UIView beginAnimations:nil context:nil]; //动画过渡时间 [UIView setAnimationDuration:2]; iv.frame=CGRectMake(50, 80, 400, 600); //动画关闭 [UIView commitAnimations]; } -(void)tapOneAct:(UITapGestureRecognizer *) sender{ NSLog(@"单击事件……"); //获取点击的View UIImageView *iv=(UIImageView*)sender.view; //动画开启 [UIView beginAnimations:nil context:nil]; //动画过渡时间 [UIView setAnimationDuration:2]; iv.frame=CGRectMake(0, 0, 100, 150); //动画关闭 [UIView commitAnimations]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- iOS开发 ☞ NSPredicate 谓词过滤
- iOS开发系列--录音
- IOS中OC与JS互相调用
- iOS 技能图谱
- Nagios 监控系列学习 ―― MRTG监控交换机流量
- IOS 二维码扫描
- Nagios 监控系列学习 ―― check_snmp_int.pl 监控交换机端口状态和流量
- iOS - Quartz2D - 视图绘制周期
- iOS中图片的一些处理,磨砂,压缩,,
- iOS申请证书,Certificates, Identifiers &Profiles 简介
- iOS 排序方法
- iOS开发系列--扩展--播放音乐库中的音乐
- iOS 自带二维码识别(识别二维码,条形码以及从相册中选择图片进行识别)
- 盘点苹果2016WWDC精彩看点, iOS 10官方细节要来了
- iOS 自带的定位系统 (设置注意事项)
- iOS 按钮点击改变背景色
- iOS之Block报错:capturing 'self' strongly in this block is likely to lead to a retain cycle
- iOS 签发证书无效问题详解
- ios 解决 dyld: Library not loaded: /System/Library/Frameworks/CoreMedia.framework/CoreMedia
- iOS navgationBar 的颜色相关设置