简体   繁体   English

CATransition转换为其他视图,在转换回时崩溃

[英]CATransition to other view works, crashes on transition back

I am using this code to transition from the current view to another and it works. 我正在使用此代码从当前视图过渡到另一个,并且可以正常工作。 The problem is that when I try to return to the current view the app crashes. 问题是当我尝试返回当前视图时,应用程序崩溃。

This is the code I use to pass from the current view to the new one: 这是我用来从当前视图传递到新视图的代码:

CATransition *transition = [CATransition animation];

transition.duration = 0.75;
// using the ease in/out timing function
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type = kCATransitionReveal;

transition.subtype = kCATransitionFromRight;

transition.delegate = self;

// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[self.view.layer addAnimation:transition forKey:nil];

// Here we hide view1, and show view2, which will cause Core Animation to animate view1 away and view2 in.

self.view.hidden = YES;

MyMessages *info1=[[MyMessages alloc] initWithNibName:@"MyMessages" bundle:nil];
[self.view addSubview:info1.view];

info1.view.hidden = NO;
self.view.hidden = NO;

I try to return using this code: 我尝试使用以下代码返回:

CATransition *transition = [CATransition animation];

transition.duration = 0.75;
// using the ease in/out timing function
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type = kCATransitionReveal;

transition.subtype = kCATransitionFromLeft;

transition.delegate = self;

// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[self.view.layer addAnimation:transition forKey:nil];

// Here we hide view1, and show view2, which will cause Core Animation to animate view1 away and view2 in.
self.view.hidden = YES;

FirstViewController *info1=[[  FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[self.view addSubview:info1.view];

info1.view.hidden = NO;
self.view.hidden = NO;

This is the code that needed to make the transition between an UIView of a UITabBarController and a new UIView . 这是在UITabBarControllerUIView和新的UIView之间进行转换所需的代码。 The code goes to a button's IBAction which exists in one of the UIView s of the UITabBarController . 该代码转到UITabBarControllerUIView之一中存在的按钮的IBAction

//initialize the app delegate

AppDelegate appDelegate = (AppDelegate) [[UIApplication sharedApplication] delegate];

// get the view that's currently showing

UIView *currentView = self.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 mynewView1
[currentView removeFromSuperview];

//assign the new view to the viewcontroller1. It is the first uiviewcontroller of the uitabbarcontroller. My uitabbarcontroller consists of five uiviewcontrollers in my project. The button exists in the first viewcontroller1 this is why i am assigning the new view to the viewcontroller1. If the button was pressed from the secondviewcontroller (viewcontroller2) of my uitabbarcontroller i will assign the new view to the secondviewcontroller (viewcontroller2) and so on...
appDelegate.viewController1=[[MyMessages alloc] initWithNibName:@"MyMessages" bundle:nil];

//add it to the window
[theWindow addSubview:appDelegate.viewController1.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"];

Thanks for you help! 感谢您的帮助! I have been trying this for more than a day to achieve it. 我已经尝试了一个多天以实现它。 I hope it will help someone with the same problem. 我希望它将对遇到相同问题的人有所帮助。

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

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