首页 > 其他 > 详细

触摸,手势

时间:2016-02-21 09:02:15      阅读:94      评论:0      收藏:0      [点我收藏+]

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 275, 500)] autorelease];
    imageView.image = [UIImage imageNamed:@"love.jpg"];
    imageView.userInteractionEnabled = YES;
    //1、创建满足需求的手势,在创建时关联手势触发时的方法
    //2、配置手势的相关属性
    //3、将手势添加w    到需要执行操作的视图上面
    //4、实现手势方法,当触摸发生,手势识别器识别到想对应的触摸时,就会执行关联的方法
    
    //轻拍手势 UITapGestureRecognizer
    UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
    //设置属性
    //1、出发手势的手指个数
    tap.numberOfTouchesRequired = 1;
    
    //2、触发手势的轻拍次数
    tap.numberOfTapsRequired = 1;
    
    //3、让imageView添加手势
    [imageView addGestureRecognizer:tap];
    
    /*
    //轻扫手势
    UISwipeGestureRecognizer *swipe = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)] autorelease];
    
    //指定轻扫的方向
//    swipe.direction = UISwipeGestureRecognizerDirectionDown;
    
    
    [imageView addGestureRecognizer:swipe];
    */
    
    /*
    //长按手势
    UILongPressGestureRecognizer *longpress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpressAction:)] autorelease];
    
    //长按手势触发的最短时间,默认是0.5
    longpress.minimumPressDuration = 1.0;
    
    [imageView addGestureRecognizer:longpress];
    */
    /*
    
    //缩放
    UIPinchGestureRecognizer *pinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)] autorelease];
    [imageView addGestureRecognizer:pinch];
    */
    /*
    //旋转
    UIRotationGestureRecognizer *rotate = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateAction:)] autorelease];
    
    
    
    
    [imageView addGestureRecognizer:rotate];
    
    */
    
    
    /*
    //平移
    UIPanGestureRecognizer *pan = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)] autorelease];
    
    
    
    [imageView addGestureRecognizer:pan];
    
    */
    

触摸,手势

原文:http://www.cnblogs.com/networkprivaate/p/5204401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!