手势

iOS中手势有

  • Tap(点一下)
  • Pinch(二指往內或往外拨动,平时经常用到的缩放)
  • Rotation(旋转)
  • Swipe(滑动,快速移动)
  • Pan (拖移,慢速移动)
  •  LongPress(长按)
UIGestureRecognizer的继承关系如下:

 在navigation中,自定义左、右控件之后出现从左向右拖动手势失效的情况,这时,

if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

            self.navigationController.interactivePopGestureRecognizer.delegate = nil;

        }

其上几个手势的回调函数基本相同,没啥太特殊的情况,多用几次就会了,没啥好说的。主要是拖动手势,

  CGPoint translation = [gesture translationInView:self.view];

    self.phoneListView.center = CGPointMake(self.phoneListView.center.x, self.phoneListView.center.y + translation.y);

    self.phoneListView.height = translation.y;

    [gesture setTranslation:CGPointZero inView:self.view];

拖动控件时需要将translation置0,或者获取gesture.state状态,得知拖动的确是发生变化了再做处理,

    if (gesture.state == UIGestureRecognizerStateChanged) {

        CGPoint translation=[gesture translationInView:self.view];//利用拖动手势的translationInView:方法取得在相对指定视图(控制器根视图)的移动

        self.upDownBtn.transform = CGAffineTransformMakeTranslation(0, translation.y);

        self.phoneListView.transform = CGAffineTransformMakeTranslation(0, translation.y);

        self.phoneListView.backgroundColor = [UIColor grayColor];

        self.phoneListView.height -= translation.y;

    }

 

 

posted on 2015-11-25 19:38  婷空万里TD  阅读(132)  评论(0编辑  收藏  举报