ios 获取UIPanGestureRecognizer的起始位置

在右滑拉开抽屉的时候,想要做到只能从屏幕边沿开始滑动拉开抽屉,需要获取UIPanGestureRecognizer的起始位置,但是系统没有提供发方法。试过在抽屉控制器的touchbegin中判断,但是当加入scrollview的子类的时候,不会调用touchbegin,判断也失效。于是有打算从滑动手势入手,自定义一个MyPanGestureRecognizer,导入UIKit/UIGestureRecognizerSubclass,重写滑动手势的touchbegin,获取起始位置。

```

#import"MyPanGestureRecognizer.h"

#import

@implementationMyPanGestureRecognizer

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{

[supertouchesBegan:toucheswithEvent:event];

UITouch* touch = [touchesanyObject];

CGPointpoint = [touchlocationInView:self.inView];

self.beginPoint= point;

}

-(instancetype)initWithTarget:(id)target action:(SEL)action inview:(UIView*)view{

self= [superinitWithTarget:targetaction:action];

if(self) {

self.inView= view;

}

returnself;

}

@end

```

你可能感兴趣的:(ios 获取UIPanGestureRecognizer的起始位置)