我正在使用一些非常标准的代码来翻转小 View 内的 2 个 UIImageView。 (我很惊讶它竟然有效!)
但是如果我在一个小 View 中有 三个 UIImageViews...并且想要在所有 3 个之间翻转怎么办?
我以为我可以剪切/粘贴我的代码的 2 个副本...但我想不行。
当我尝试翻转 1>2.. 然后 2>3... 它只翻转一次... 直接从 1>3 开始。
2怎么了????
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image1 removeFromSuperview];
[myView addSubview:image2];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];
最佳答案
动画不是这样链接在一起的。基本上,他们同时制作两个动画。您想要的是为第二次翻转创建一个新方法,该方法将在第一次翻转完成后调用:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)contextn {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];
}
然后在现有方法中添加以下行:
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
像这样:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[image1 removeFromSuperview];
[myView addSubview:image2];
[UIView commitAnimations];
有关更多信息,请查看apple docs
关于iphone - 在图像 1、2、3(而不是图像 1,3)之间翻转(iPhone SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2249688/