手势

来源:互联网 发布:婚礼送多少钱 知乎 编辑:程序博客网 时间:2024/05/01 07:13
手势
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
原创粉丝点击