ShouldAutorotate not called on view controller

I have a simple application consisting of a single view controller. I started with the Single View Application Xcode 7 GM application template, but then removed the main storyboard and set up my view controller as follows:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let vc = ViewController()

    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    window!.rootViewController = vc
    window!.makeKeyAndVisible()

    return true
}

In my information plist, I have all the orientations indicated in the Orientation section of the supported interfaces section, and the application rotates to all orientations on the iPad.

However, in my simple methods vidaยน Manager shouldAutorotate()and supportedInterfaceOrientations()are never called. This is a problem because I am experimenting with user interface controls that enable and disable automatic rotation. What can prevent these methods from being called?

Sample project here (requires Swift 2)


ยนnon- UINavigationController

+4
3

Apple Developer, iPad ( iOS 9), :

https://forums.developer.apple.com/message/13508#13508

, , , . , , , , , .

, . , , , , .

, self.navigationController.view.superview.superview, , - . , , . , , . YMMV.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    self.startingInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [self updateLayoutsForCurrentOrientation:toInterfaceOrientation view:self.navigationController.view.superview.superview];
}

- (void)updateLayoutsForCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation view:(UIView *)view {
    CGAffineTransform transform = CGAffineTransformIdentity;

    if (self.startingInterfaceOrientation == UIInterfaceOrientationPortrait) {
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                transform = CGAffineTransformMakeRotation(M_PI/2.0f);
                break;
            case UIInterfaceOrientationLandscapeRight:
                transform = CGAffineTransformMakeRotation(-M_PI/2.0f);
                break;
            case UIInterfaceOrientationPortrait:
                transform = CGAffineTransformIdentity;
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                transform = CGAffineTransformMakeRotation(M_PI);
                break;
            default:
                break;
        }
    }
    else if (self.startingInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                transform = CGAffineTransformMakeRotation(-M_PI/2.0f);
                break;
            case UIInterfaceOrientationLandscapeRight:
                transform = CGAffineTransformMakeRotation(M_PI/2.0f);
                break;
            case UIInterfaceOrientationPortrait:
                transform = CGAffineTransformMakeRotation(M_PI);
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                transform = CGAffineTransformIdentity;
                break;
            default:
                break;
        }
    }
    else if (self.startingInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                transform = CGAffineTransformIdentity;
                break;
            case UIInterfaceOrientationLandscapeRight:
                transform = CGAffineTransformMakeRotation(M_PI);
                break;
            case UIInterfaceOrientationPortrait:
                transform = CGAffineTransformMakeRotation(-M_PI/2.0f);
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                transform = CGAffineTransformMakeRotation(M_PI/2.0f);
                break;
            default:
                break;
        }
    }
    else if (self.startingInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                transform = CGAffineTransformMakeRotation(M_PI);
                break;
            case UIInterfaceOrientationLandscapeRight:
                transform = CGAffineTransformIdentity;
                break;
            case UIInterfaceOrientationPortrait:
                transform = CGAffineTransformMakeRotation(M_PI/2.0f);
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                transform = CGAffineTransformMakeRotation(-M_PI/2.0f);
                break;
            default:
                break;
        }
    }
    view.transform = transform;
}

Jared Sinclair JTSImageViewController ( ), MIT github : https://github.com/jaredsinclair/JTSImageViewController

+5

: fooobar.com/questions/86749/...

, info.plist iPhone iPad.

0

To opt out of the slideshow and split, add the UIRequiresFullScreen key to the Xcode project Info.plist file and apply the logical value YES.

0
source

Source: https://habr.com/ru/post/1607049/


All Articles