2013-12-14 22 views
0

我有一個UIViewController其中包含一個按鈕。單擊該按鈕時,它將以modal(上移過渡)轉換爲TabViewController,其中有兩個選項卡項目。滑下模態導航

在這兩個標籤項目上,我有一個關閉按鈕,我想在其上轉換回上面提到的UIViewController,但是在下滑過渡中。

我該怎麼做?

回答

0

從與關閉按鈕的視圖控制器,請撥打本時提高了按鈕的UIControlEventTouchUpInside事件:

[self.parentViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 
1

讓我們說,你有按鈕接近目標爲dismissMe

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
button.frame = CGRectMake(0, 0, 100, 75); 
button.titleLabel.text = @"Close"; 
[button setBackgroundColor:[UIColor greenColor]]; 
button.center = self.view.center; 
[button addTarget:self action:@selector(dismissMe) forControlEvents:UIControlEventTouchUpInside]; 
[self.view addSubview:button]; 

然後請將以下代碼添加到目標方法。

-(void)dismissMe { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

你也可以用這個代替

[self.parentViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];