这是 panGesture 的实例。
pangstr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
- (void)handlePan:(UIPanGestureRecognizer *)recognizer{
CGPoint translation = [recognizer translationInView:baseView];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:baseView];
if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [recognizer velocityInView:baseView];
CGFloat magnitude = sqrtf((velocity.x * velocity.x));
CGFloat slideMult = magnitude / 1000;
NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult);
float slideFactor = 0.15 * slideMult;
CGPoint finalPoint = CGPointMake(recognizer.view.center.x + (velocity.x * slideFactor),
recognizer.view.center.y + (velocity.y * slideFactor));
}
现在我的问题是如何在 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 函数中使用 (panGestureRecogniser *)recogniser 参数。我特别想要这个,因为我想在我的 TouchesMoved 函数中获取 finalPoint 的值,而 CGPoint finalPoint 使用 *recogniser 参数。
如果有人能给我一个解决方案,那就太好了谢谢