关闭

手势

57人阅读 评论(0) 收藏 举报
手势
addGestureRecognizer:给视图添加手势,然后再实现@selector( )里的方法 

    轻拍(tap)

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

    //设置轻拍次数(默认1)(按2次好使)

    tap.numberOfTapsRequired = 2;

    //设置轻拍的手指个数(默认1)

 // tap.numberOfTouchesRequired = 2;

    轻扫(swipe)

    //默认从左往右

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];

    [imageView addGestureRecognizer:swipe];

    //要么上下一起 要么左右一起(下面的写法只能执行左右)

    swipe.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionUp;

    //设置轻扫手指个数

    swipe.numberOfTouchesRequired = 2;

    捏合(pinch

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];

    [imageView addGestureRecognizer:pinch];

    旋转 (Rotation)

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];

    [imageView addGestureRecognizer:rotation];

     平移(Pan)

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

    [imageView addGestureRecognizer:pan];

   长按(LongPress)

    UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpress:)];

    [imageView addGestureRecognizer:longpress];

    //长按时间

    longpress.minimumPressDuration = 1;


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:861次
    • 积分:108
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论