2013-02-14 153 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. 在回調中,彈出視圖控制器。

警告:這是非標準的用戶界面。最好使用標準導航欄和後退按鈕。