您的位置:首页 > 移动开发 > IOS开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: