题
请考虑以下代码,并告诉我我在做什么错误的。
我要到翻两UIViews.
不知怎的,当我离开的初步看法,我只是得到翻看,没有动画。当我翻转回来,动画显示。
翻转所触发的按钮上的意见本身。
- (IBAction)showMoreInfo:(id)sender
{
UIView *moreInfo = self.flipView;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
[parent addSubview:moreInfo];
[UIView commitAnimations];
}
- (IBAction)showLessInfo:(id)sender
{
UIView *lessInfo = self.view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.flipView cache:YES];
UIView *parent = self.flipView.superview;
[self.flipView removeFromSuperview];
[parent addSubview:lessInfo];
[UIView commitAnimations];
}
解决方案
这可能是因为你没有使用的容器视为过渡图。参考文件 setAnimationTransition:forView:高速缓存:
如果你想改变的观的景期间过渡,例如,从一种看到另一个—然后使用的容器视的一个实例),如下:
- 开始一个动画块。
- 设置过渡容器上查看。
- 除子视图从容器中来看。
- 添加新子视图的容器景。
- 提交的动画块。
尝试使用 self.view.superview
在动画的过渡图 showMoreInfo:
的原因 showLessInfo:
方法工作是您使用的是一个容器景。
其他提示
您可以使用您的主窗口(一个UIWindow)作为容器视图从一个UIWindow UIView的天赋?
另外iPhone 3.0经由presentModalViewController方法引入的倒装事务:
CustomViewController *vc = [[CustomViewController alloc]
initWithNibName:@"CustomViewController" bundle:nil];
vc.delegate = self;
// The magic statement. This will flip from right to left.
// present the modal view controller then when you dismissModalViewController
// it will transition flip from left to right. Simple and elegant.
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:vc animated:YES];
[vc release];
后的iOS 4.0,可以在视图之间与该翻转:
[UIView transitionFromView:sourceView toView:destinationView duration:0.35f options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
NSLog(@"I just flipped!");
}];
如杰森提到的,则需要此到容器视图内发生。
不隶属于 StackOverflow