在强制定位之前,如何更改方向

时间:2014-05-01 08:26:24

标签: objective-c ios7 uiinterfaceorientation

我有这个代码可以正常工作,除非你从肖像进入视图控制器然后它保持纵向。一旦它进入视图控制器去景观并保持景观,我就需要它。

- (NSUInteger)supportedInterfaceOrientations {
    if (self.isFlexiGram) {
        return UIInterfaceOrientationMaskLandscape;
    } else {
        return UIInterfaceOrientationMaskAll;
    }

}

- (BOOL)shouldAutorotate {
    return YES;
}

我正在使用以下方法更改容器视图控制器

#pragma mark - Container Controller Methods
- (void)presentDetailController:(UIViewController*)detailVC{

    //0. Remove the current Detail View Controller showed
    if(self.currentDetailViewController){
        [self removeCurrentDetailViewController];
    }

    //1. Add the detail controller as child of the container
    [self addChildViewController:detailVC];

    //2. Define the detail controller's view size
    detailVC.view.frame = [self frameForDetailController];

    //3. Add the Detail controller's view to the Container's detail view and save a reference to the detail View Controller
    [self.containerView addSubview:detailVC.view];
    self.currentDetailViewController = detailVC;

    //4. Complete the add flow calling the function didMoveToParentViewController
    [detailVC didMoveToParentViewController:self];
}

- (void)removeCurrentDetailViewController{

    //1. Call the willMoveToParentViewController with nil
    //   This is the last method where your detailViewController can perform some operations before neing removed
    [self.currentDetailViewController willMoveToParentViewController:nil];

    //2. Remove the DetailViewController's view from the Container
    [self.currentDetailViewController.view removeFromSuperview];

    //3. Update the hierarchy"
    //   Automatically the method didMoveToParentViewController: will be called on the detailViewController)
    [self.currentDetailViewController removeFromParentViewController];
}

我已经尝试过preferredInterfaceOrientationForPresentation,但是因为我没有使用presentViewController而没有调用它。

我尝试了以下问题

Forcing UIInterfaceOrientation changes on iPhone IOS 6 force device orientation to landscape

我还浏览了苹果文档

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html

0 个答案:

没有答案