如何翻转单个UIView(不翻转父视图) [英] How to flip an individual UIView (without flipping the parent view)
问题描述
这是一个iPad项目,我有一个带有几个子视图的UIView,我试图使用[UIView transitionFromView:toView:duration:options:completion]为其中一个UIViews制作动画,但当我运行此方法时,整个父项视图被翻转!
这是我正在使用的代码:
This is an iPad project where I have a UIView with several subViews, and I am trying to animate one of this UIViews using [UIView transitionFromView:toView:duration:options:completion], but when I run this method the whole parent view gets flipped! This is the code I'm using:
UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 300, 300)];
[newView setBackgroundColor:[UIColor redColor]];
[UIView transitionFromView:self.firstView.view toView:secondView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
如何在不动画整个父视图的情况下在这些视图之间切换?
谢谢!
Any idea on how can I flip between this views without animating the whole parent view? Thanks!
推荐答案
此代码可以帮助您:
将要翻转的两个视图放在一个大小为
的未命名视图中,并将 IBOutlet UIView * newView,* oldView;
链接到视图和将新视图置于顶部
put the two views you want to flip inside an unnamed view with the same size
and link the IBOutlet UIView *newView,*oldView;
to the views and put the new view on top
bool a = NO;
@implementation ViewController
- (IBAction)flip:(id)sender
{
if (a == NO) {
[UIView transitionFromView:oldView toView:newView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:NULL];
a = YES; // a = !a;
}
else {
[UIView transitionFromView:newView toView:oldView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:NULL];
a = NO; // a = !a;
}
}
这篇关于如何翻转单个UIView(不翻转父视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!