我是 iPhone 开发的新手,我正在尝试在 UIView 和另一个包含常规 UIView 和 UIScrollView 的 UIView 之间制作翻转动画,滚动视图又具有几个 UIView 作为子视图。
在动画开始之前,滚动视图需要偏移到特定点以显示特定的子视图(用户正在跳转到滚动视图中的特定“章节”)。
它的动画效果很好,但问题是它会“有时”(也许每三次)使用滚动视图的子视图之一启动动画,而不是使用原始 UIView(下面代码中的“overlayView”)启动动画)。我怀疑这与我在动画之前设置滚动视图的偏移量有关。
这就是我目前的做法:
// get the MPMoviePlayer window that has the views to animate between as subviews
UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
// tell the controller of the scroll view to set the scroll view offset
[instructionControlsController setInstructionImageWithNumber:[self chapterAtTime:currentTime]];
// Animate transition to instruction view
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView: moviePlayerWindow cache:NO];
// the views to animate between
[moviePlayerWindow sendSubviewToBack: overlayView];
[moviePlayerWindow bringSubviewToFront: instructionControlsController.view];
[UIView commitAnimations];
控制器中的 setInstructionImageWithNumber 方法如下所示:
- (void) setInstructionImageWithNumber:(int)number
{
if (number < kNumberOfPages)
[scrollView setContentOffset: CGPointMake((number * kImageWidth), 0) animated:NO];
}
关于我可能做错了什么以及为什么我会在动画有时看起来很好有时不正常的情况下出现这种行为的任何想法?