2013-02-14 158 views
0

我有两个viewController:FirstViewController和SecondViewController添加手势识别器

我做了一个动画,使视图从右到左。

我要当一个让扫到右SecondViewController显示和隐藏FirstViewController

的动画作品有代码

SecondViewController *secondViewController = [[SecondViewController alloc]  initWithNibName:@"PlayListController" bundle:nil]; 
// Set up view2 
secondViewController.view.frame = self.view.frame; 
secondViewController.view.center = CGPointMake(self.view.center.x + CGRectGetWidth(self.view.frame), self.view.center.y); 
[self.view.superview addSubview:secondViewController.view]; 
// Animate the push 
[UIView beginAnimations: nil context: NULL]; 
[UIView setAnimationDelegate: self]; 
[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)]; 
secondViewController.view.center = self.view.center; 
self.view.center = CGPointMake(self.view.center.x - CGRectGetWidth(self.view.frame), self.view.center.y); 
[UIView commitAnimations]; 

我添加了一个按钮,隐藏与动画中的观点,但它不起作用?

+1

你为什么给我们的代码有效,但不给我们你正在努力的代码? – 2013-02-14 13:12:26

+0

以这种方式进行转换的尝试存在问题(视图层次结构与控制器层次结构不同步,您将不会收到某些事件,内存管理问题等)。你应该只使用导航控制器,如果你不想看导航栏,那么[隐藏它](http://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/的reference.html#// apple_ref/DOC/UID/TP40006934-CH3-SW9)。你正在做很多工作来复制比你自己的尝试更强大的标准行为。 – Rob 2013-02-14 15:06:13

回答

0
  1. 将手势识别器添加到您的视图中。
  2. 在回调中,弹出视图控制器。

警告:这是非标准的用户界面。最好使用标准导航栏和后退按钮。