基本上我试着把你的手指放在地球上,然后旋转它的类型函数。
所以我真正需要做的就是用一个很短的计时器(?500ms?)抓取滑动的方向和速度。
所以就像这样
While(swiping) {
Get(pointTouched);
swipeDirection = Calc(direction);
swipeSpeed = Calc(speed);
FramesToPlay = swipeSpeed * ConstantAmount;
If(Direction == Backwards){
FramesToPlay = FramesToPlay * -1;
}
Play(playAnimation, FramesToPlay);
wait(500ms);
}有人知道这样的事吗?或者任何我可以拼凑起来的碎片?
我已经弄明白了这个动画,只是这个滑动的细节让我有点困惑。
发布于 2011-02-02 02:17:55
您可能会使用具有velocityInView:方法的UIPanGestureRecognizer。我还没有测试过,但是看起来应该可以工作了:
- (void)handlePanGesture:(UIPanGestureRecognizer *)pan
{
if (pan.state == UIGestureRecognizerStateEnded)
{
CGPoint vel = [pan velocityInView:self.view];
[self doSpinAnimationWithVelocity:vel.x];
}
}此外,当pan.state == UIGestureRecognizerChanged时,您可以让您的地球随着手指一起旋转。
发布于 2011-02-02 01:35:44
在当前UIView中使用touchesBegan和touchesMoved委托。这些代理返回xy位置和时间戳。您可以通过将触摸之间的毕达哥拉斯距离除以增量时间来估计触摸或滑动的速度,并从atan2(dy,dx)获得角度。您还可以通过对多个触摸事件执行此操作来平均或过滤返回的速度。
发布于 2011-02-02 02:05:04
我是这样做的:创建一个UISwipeGestureRecognizer的子类。这个子类的目的仅仅是记住它在其touchesBegan:withEvent:方法中接收的第一个也是最后一个UITouch对象。其他的都会被转发到super上。
当识别器触发其操作时,识别器将作为sender参数传入。您可以向它询问初始和最终的触摸对象,然后使用locationInView:方法和timestamp属性计算出滑动的速度(速度=距离的变化/时间的变化)。
所以应该是这样的:
@interface DDSwipeGestureRecognizer : UISwipeGestureRecognizer
@property (nonatomic, retain) UITouch * firstTouch;
@property (nonatomic, retain) UITouch * lastTouch;
@end
@implementation DDSwipeGestureRecognizer
@synthesize firstTouch, lastTouch;
- (void) dealloc {
[firstTouch release];
[lastTouch release];
[super dealloc];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self setFirstTouch:[touches anyObject]];
[super touchesBegan:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self setLastTouch:[touches anyObject]];
[super touchesEnded:touches withEvent:event];
}
@end然后在其他地方你会这样做:
DDSwipeGestureRecognizer *swipe = [[DDSwipeGestureRecognizer alloc] init];
[swipe setTarget:self];
[swipe setAction:@selector(swiped:)];
[myView addGestureRecognizer:swipe];
[swipe release];你的动作应该是这样的:
- (void) swiped:(DDSwipeGestureRecognizer *)recognizer {
CGPoint firstPoint = [[recognizer firstTouch] locationInView:myView];
CGPoint lastPoint = [[recognizer lastTouch] locationInView:myView];
CGFloat distance = ...; // the distance between firstPoint and lastPoint
NSTimeInterval elapsedTime = [[recognizer lastTouch] timestamp] - [[recognizer firstTouch] timestamp];
CGFloat velocity = distance / elapsedTime;
NSLog(@"the velocity of the swipe was %f points per second", velocity);
}警告:在浏览器中键入但未编译的代码。警告实施者。
https://stackoverflow.com/questions/4863599
复制相似问题