ios: Custom Segue between two viewcontrollers in landscape mode

后端 未结 2 680
一向
一向 2021-02-05 13:45

I have two UIViewControllers that are contained in a navigatoin view controller and both in landscape mode. I want to switch between two uiviewcontroller without have an animati

相关标签:
2条回答
  • 2021-02-05 14:28

    you can have the destination view controller take the center/transform/bounds from the source controller (Which is already oriented properly):

    -(void) perform{
        self.appDelegate = [[UIApplication sharedApplication] delegate];
        UIViewController *src = (UIViewController *) self.sourceViewController;
        UIViewController *dst = (UIViewController *) self.destinationViewController;
    
    // match orientation/position
    dst.view.center = src.view.center;
    dst.view.transform = src.view.transform;
    dst.view.bounds = src.view.bounds;
    
    [dst.view removeFromSuperview];
    [self.appDelegate.window addSubview:dst.view];
    self.appDelegate.window.rootViewController=dst;
    }
    
    0 讨论(0)
  • 2021-02-05 14:51

    The code above doesn't work because the destinationViewController cannot receive updates from UIInterfaceOrientation on it's own. It receives those updates through it's "Container View Controller" (the Navigation Controller). To get the custom segue to work properly, we need to transition to the new view through the Navigation Controller.

    -(void) perform{
        [[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO];
    }
    
    0 讨论(0)
提交回复
热议问题