简体   繁体   English

CATransition的ios代码只能在第一次使用?

[英]ios code for CATransition works only the first time?

I use this code to make the transition from one view to another in ios sdk but it is working only the first time, when i return back to the previous view it does not work although the code is triggered... 我使用此代码在ios sdk中从一个视图过渡到另一个视图,但它仅在第一次工作,当我返回到上一个视图时,尽管触发了代码,但它不起作用...

UIView *currentView = self.viewController1.view; UIView * currentView = self.viewController1.view;

// get the the underlying UIWindow, or the view containing the current view view
UIView *theWindow = [currentView superview];

// remove the current view and replace with myView1
[currentView setHidden:TRUE];//hide previous view diladi to tabviewcontroller
self.viewController1=[[MyFriendProfile alloc] initWithNibName:@"MyFriendProfile" bundle:nil];
[theWindow addSubview:self.viewController1.view];
[currentView setHidden:FALSE]; 
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView2"];

Any help Appreciated! 任何帮助表示赞赏!

I have found the answer here is the code... 我在这里找到答案是代码...

//get viewcontroller1 view //获取viewcontroller1视图

UIView *currentView = self.viewController1.view; UIView * currentView = self.viewController1.view;

// get the the underlying UIWindow, or the view containing the current view view
UIView *theWindow = [currentView superview];

// remove the current view and replace with myView1
[currentView setHidden:TRUE];//hide previous view diladi to tabviewcontroller


MyFriendProfile *test1=[[MyFriendProfile alloc] initWithNibName:@"MyFriendProfile" bundle:nil];


[theWindow addSubview:test1.view];


// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM