CATransition 到其他视图有效,但转换回来时崩溃

发布于 2024-12-11 18:13:53 字数 1812 浏览 0 评论 0原文

我正在使用此代码从当前视图转换到另一个视图,并且它有效。问题是,当我尝试返回当前视图时,应用程序崩溃了。

这是我用来从当前视图传递到新视图的代码:

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;

我尝试使用以下代码返回:

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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春庭雪 2024-12-18 18:13:53

这是在 UITabBarControllerUIView 和新 UIView 之间进行转换所需的代码。该代码转到按钮的 IBAction,该按钮存在于 UITabBarControllerUIView 之一中。

//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"];

谢谢你的帮助!为了实现这一目标,我已经尝试了一天多了。我希望它能帮助有同样问题的人。

This is the code that needed to make the transition between an UIView of a UITabBarController and a new UIView. The code goes to a button's IBAction which exists in one of the UIViews of the UITabBarController.

//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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文