阅读背景:

IOS学习之——Gesture手势基础_架构师之路

来源:互联网 
//
//  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
//
//  MyViewController.m
//  网络NSUIrConnect
//



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: