2014-09-01 103 views
1

第一次海報,長時間觀察員。故事板Segue過渡效果

我正在爲目前正在使用的應用程序使用故事板,並且需要更多的轉換而不僅僅是前進,特別是要回溯。每當我使用這個segue時,我必須返回一個菜單,點擊下一個按鈕轉到另一個ViewController,將崩潰整個應用程序!

不知道怎麼回事,我在實現文件

#import "SlideLeftSegue.h" 

@implementation SlideLeftSegue 

- (void)perform{ 
    UIView *sv = ((UIViewController *)self.sourceViewController).view; 
    UIView *dv = ((UIViewController *)self.destinationViewController).view; 

    UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; 
    dv.center = CGPointMake(sv.center.x - sv.frame.size.width, dv.center.y); 
    [window insertSubview:dv belowSubview:sv]; 

    [UIView animateWithDuration:0.4 
        animations:^{ 
         dv.center = CGPointMake(sv.center.x, 
               dv.center.y); 
         sv.center = CGPointMake(sv.center.x + sv.frame.size.width, 
               dv.center.y); 
        } 
        completion:^(BOOL finished){ 
         [[self destinationViewController] 
          dismissViewControllerAnimated:NO completion:nil]; 
        }]; 
} 

@end 

使用此這是我的頭文件

#import <UIKit/UIKit.h> 

// Move to the previous screen with slide animation. 

@interface SlideLeftSegue : UIStoryboardSegue 

@end 

我還在學習,所以如果你有任何想法發生了什麼,id欣賞初學者水平的解釋。

回答

4

可以實現與更少的代碼

爲了呈現一個視圖控制器:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"ViewID"]; 
view.modalTransitionStyle = UIModalTransitionStyleCoverVertical; // you can try the other 3 UIModalTransitionStyle too 
[self presentViewController:view animated:YES completion:nil]; 

要回去:

[self dismissViewControllerAnimated:YES completion:nil]; 
+0

我做到了,這就是它在我吐回。 爲「SlideLeftSegue」不可見@interface聲明選擇「dismissViewControllerAnimated:完成:」 – Jlentriken 2014-09-01 11:12:10

+0

僅供參考,當它嘗試使用SlideLeftSegue屏幕之間移動崩潰,它說 「主題1:EXC_BAD_ACCESS(代碼= EXC_I386_GPFLT)」 – Jlentriken 2014-09-01 11:17:37

+0

我所理解的是,你試圖通過按下某種按鈕來表示視圖。在故事板中,爲什麼不在源視圖控制器中設置按鈕,然後將按鈕與Command-拖動到目標視圖相連接。之後,回到你的源代碼VC,使用上面的代碼。 – 2014-09-01 11:33:15