请考虑下面的代码,并告诉我我做错了什么。
我想在两个 UIView 之间切换。
不知何故,当我从初始视图翻转时,我只是得到翻转的视图,没有动画。当我向后翻转时,动画显示得很好。
翻转是由视图本身上的按钮触发的。
- (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:缓存: http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/setAnimationTransition:forView:cache:
如果要在转换期间更改视图的外观(例如,从一个视图翻转到另一个视图),则使用容器视图(UIView 的实例),如下所示:
- 开始一个动画块。
- 在容器视图上设置过渡。
- 从容器视图中删除子视图。
- 将新的子视图添加到容器视图中。
- 提交动画块。
尝试使用self.view.superview
在动画过渡视图中showMoreInfo:
原因是showLessInfo:
方法的工作原理是您使用的是容器视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)