我正在使用 Xcode 4.4 和 ARC 开发基于页面的 iPhone 应用程序,并且已经在这方面停留了一段时间。在某个页面上,UIImageView手指需要向上滑动并指向某物,然后向左滑动离开屏幕。当我运行一次时,它按预期工作,但是当我翻页并返回时 - 现在有 2 个手指彼此滑动约 0.5 秒,不同步。
代码如下:
-(void)fingerSwipeUp:(UIImageView *)imageView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[imageView setCenter:CGPointMake(213.75,355.5)];
[UIView commitAnimations];
}
-(void)fingerSwipeLeft:(UIImageView *)imageView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[imageView setCenter:CGPointMake(-80,355.5)];
[UIView commitAnimations];
}
UIImageView *finger = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"finger.png"]];
// position finger off the screen
[finger setFrame:CGRectMake(142.5,480,152.5,243)];
[self.view addSubview:finger];
[self performSelector:@selector(fingerSwipeUp:) withObject:finger afterDelay:6];
[self performSelector:@selector(fingerSwipeLeft:) withObject:finger afterDelay:8];
非常感谢任何帮助
最佳答案
我猜您正在 ViewDidAppear() 中创建“手指” View ?如果是这种情况,每次翻页(隐藏)然后返回时,您都会添加另一个箭头( subview )。那么这个呢:
if (finger == nil) {
finger = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"finger.png"]];
[finger setFrame:CGRectMake(142.5,480,152.5,243)];
[self.view addSubview:finger];
}
[self performSelector:@selector(fingerSwipeUp:) withObject:finger afterDelay:6];
[self performSelector:@selector(fingerSwipeLeft:) withObject:finger afterDelay:8];
关于objective-c - iOS 滑动动画意外发生两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12388565/