Iphone 使用CATTransition从右向左和向后转换?

Iphone 使用CATTransition从右向左和向后转换?,iphone,objective-c,ios,Iphone,Objective C,Ios,我有一个UIAbbarController,它由五个UIViewController组成 当我在第一个uiviewcontroller的视图中点击一个按钮时,我希望uiviewcontroller隐藏,并添加一个新的uiviewcontroller,从右向左过渡。我已经做到了这一点,但当我点击新视图上的按钮时,应用程序崩溃!!!按钮上没有附加代码。我收到EXEC\u BAD\u访问错误 有人知道为什么会发生这种情况,以及如何用新的观点克服这个问题吗 当我尝试modalview转换时,视图功能正常

我有一个UIAbbarController,它由五个UIViewController组成

当我在第一个uiviewcontroller的视图中点击一个按钮时,我希望uiviewcontroller隐藏,并添加一个新的uiviewcontroller,从右向左过渡。我已经做到了这一点,但当我点击新视图上的按钮时,应用程序崩溃!!!按钮上没有附加代码。我收到EXEC\u BAD\u访问错误

有人知道为什么会发生这种情况,以及如何用新的观点克服这个问题吗

当我尝试modalview转换时,视图功能正常。当我尝试使用CATTransition时会发生这种情况。我需要CATTransition,因为modalview过渡没有从右到左或从左到右的过渡


感谢您的帮助

我认为您可能没有正确保留新的视图控制器。
但是,有没有理由不使用UINavigatonController和pushViewController/popViewController?这将使事情变得更容易

您可能在发布“新视图”时遇到问题,您指的是视图控制器,而不是控制器的视图

我猜你在尝试这样的事情(或者只是举个例子):

您释放了新的视图控制器(插入子视图不会增加重新计数),因此当您执行操作(点击按钮)时,目标(newVC)已被释放,这会产生此错误


因此,您所要做的就是创建对该视图控制器的引用(例如,将其分配给某个保留属性)。以模态方式执行此操作时,显示模态的视图控制器会自动将引用保留在self.modalViewController中。

这是在tabviewcontroller的Uiview和新Uiview之间进行转换所需的代码。代码转到tabviewcontroller的一个UIView中存在的按钮的iAction

//初始化应用程序委托

AppDelegate AppDelegate=(AppDelegate)[[UIApplication sharedApplication]委托]

//获取当前显示的视图

UIView*currentView=self.view

//获取基础UIWindow或包含当前视图的视图

UIView*窗口=[currentView superview]

// remove the current view and replace with mynewView1
[currentView removeFromSuperview];
//将新视图指定给viewcontroller1。它是UIDABBARCONTROLLER的第一个UIVIEW控制器。在我的项目中,我的UIAbbarController由五个UIViewController组成。 该按钮存在于第一个viewcontroller1中,这就是我将新视图指定给viewcontroller1的原因。如果从我的uitabbarcontroller的secondviewcontroller(viewcontroller2)按下该按钮,我会将新视图分配给secondviewcontroller(viewcontroller2),依此类推

appDelegate.viewController1=[[MyMessages alloc] initWithNibName:@"MyMessages" bundle:nil];
//将其添加到窗口中

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

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

请检查我的ASN,我无法将其作为评论发布
[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"];