我在另一个内部有一个uiview。我的子视图上有一个按钮(我已将我的子视图连接到我创建的iboutlet uiview),当我点击它时,我希望在其位置可以看到新视图。我使用这段代码,但是当我点击它时,我看到白色空白!
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:mysubview cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1.view cache:YES];
[UIView setAnimationDuration: 1.5];
[UIView commitAnimations];
mysubview.hidden = YES;
newview1.view.hidden = NO;
任何帮助表示赞赏!
答案 0 :(得分:0)
父视图应该能够使用以下方式切换出它的子视图:
transitionFromView:toView:duration:options:completion:
使用给定参数在指定视图之间创建过渡动画。
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration: (NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
答案 1 :(得分:0)
我在几个小时后得到了它!
以下是代码:
//获取当前视图
UIView * currentView = mysubview;
// hide the previous view
[currentView setHidden:TRUE];
//初始化下一个视图
MyMessages *view1=[[MyMessages alloc] initWithNibName:@"MyMessages" bundle:nil];
[currentView addSubview:view1.view];//add next view to current
[currentView setHidden:FALSE];//show current (actually it should be the next view because we added as a subview)
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];//show up the new view from right side (this type of effect happens in navigationcontrollers)
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//
[[currentView layer] addAnimation:animation forKey:@"SwitchToView1"];