我正在使用Apple的开发网站上的PageControl项目。我在项目中添加了一个翻转视图,并在每个视图/页面的右上角添加了一个信息图标。出于某种原因,只有第一页能够为翻动设置动画。第2页仍显示翻页但不动画。为了确保第1页没有什么特别之处,我切换了第1页和第2页,并且工作正常。位置1中的第2页是动画,而位置2中的第1页则没有。任何想法为什么会发生这种情况或我如何解决它?
我确实看过这个帖子,这似乎是同一个问题:Flip View Iphone。但是,我的flipview是一个UIViewController,因此是带有信息图标的类。在另一个线程中,他们使用的是UIViews。
我确实从上面的线程实现了showInfo代码。在第2页上,我看不到翻转。然后我滚动到第1页,看到它已翻转。不知道为什么它不会停留在第2页。当在第1页时,它没有动画翻转。翻转视图突然出现了。
答案 0 :(得分:1)
你有一个containerView吗?可以存在的东西,以便您可以添加和删除子视图?如果你有两个viewControllers,一个进入,一个进行,没有containerView,动画可能会中断。我使用rootViewController并使用后面的rootViewcontroller为我和我的所有页面设置动画。这是我的翻转代码,你可能需要做一些编辑才能让它适合你:
(请记住,self是rootViewcontroller,一个带有空白视图的viewcontroller(颜色与视图匹配))
- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2
{
/*
This method is called to switch views.
It flips the displayed view from the main view to the flipside view and vice-versa.
*/
UIViewController *coming = nil;
UIViewController *going = nil;
UIViewAnimationTransition transition;
[view1.view setUserInteractionEnabled: NO];
[view2.view setUserInteractionEnabled: NO];
if (view1.view.superview == nil) {
coming = view1;
going = view2;
transition = UIViewAnimationTransitionFlipFromLeft;
}
else {
coming = view2;
going = view1;
transition = UIViewAnimationTransitionFlipFromRight;
}
// in some cases the following is needed to size the view
// coming.view.frame = [UIScreen mainScreen].applicationFrame;
// going.view.alpha = 1.0; //uncomment these lines if we want fading of views
// coming.view.alpha = 0.0;
NSArray *viewArray = [[NSArray alloc] initWithObjects:coming, going, nil];
[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[UIView beginAnimations:@"View Flip" context:viewArray]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// coming.view.alpha = 1.0; //uncomment these lines if we want fading of views
// going.view.alpha = 0.0;
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[self.view addSubview: coming.view];
}
[UIView commitAnimations];
}
- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
NSArray *viewArray = context;
[((UIViewController *)[viewArray objectAtIndex:1]).view removeFromSuperview];
[[viewArray objectAtIndex:1] viewDidDisappear:YES];
[[viewArray objectAtIndex:0] viewDidAppear:YES];
[[[viewArray objectAtIndex:0] view] setUserInteractionEnabled: YES];
[viewArray release];
}