[英]ios UISwipeGestureRecognizer calculate offset
我正在为我的应用程序添加滑动手势识别器
- (void)createGestureRecognizers
{
//adding swipe up gesture
UISwipeGestureRecognizer *swipeUpGesture= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpGesture:)];
[swipeUpGesture setDirection:UISwipeGestureRecognizerDirectionUp];
[self.view addGestureRecognizer:swipeUpGesture];
[swipeUpGesture release];
}
以及处理滑动事件的方法:
-(IBAction)handleSwipeUpGesture:(UISwipeGestureRecognizer *)sender
{
NSLog(@"handleSwipeUpGesture: called");
}
我该如何计算偏移? 移动视图?
UISwipeGestureRecognizer的UIGestureRecognizer抽象超类有着愚蠢的方法
- (CGPoint)locationInView:(UIView *)view
- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view
这允许您知道手势在视图中的位置,但这是一个离散的手势识别器(无论您想要调用它,您都无法控制,它会以给定的“平移”或“偏移”触发)。 听起来你正在寻找连续控制,为此你需要一个UIPanGestureRecognizer ,它有以下方法(为你做翻译计算)
- (CGPoint)translationInView:(UIView *)view
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view
- (CGPoint)velocityInView:(UIView *)view
然后,当手势不断展开时,您将获得快速回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.