请考虑下面的代码,并告诉我我做错了什么.
我想在两个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];
}
Run Code Online (Sandbox Code Playgroud)
Jas*_*wig 17
这可能是因为您没有使用容器视图作为转换视图.请参阅有关setAnimationTransition:forView:cache的文档:
如果要在转换期间更改视图的外观(例如,从一个视图翻转到另一个视图),则使用容器视图(UIView的实例),如下所示:
- 开始动画块.
- 在容器视图上设置转换.
- 从容器视图中删除子视图.
- 将新子视图添加到容器视图中.
- 提交动画块.
尝试self.view.superview
在动画过渡视图中使用showMoreInfo:
该showLessInfo:
方法有效的原因是您正在使用容器视图.
Suk*_*ima 12
你可以使用你的MainWindow(UIWindow)作为UIView的UIWindow内容的容器视图吗?
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];
Run Code Online (Sandbox Code Playgroud)