Custom UIWindows do not rotate correctly in iOS 8

前端 未结 4 584
情歌与酒
情歌与酒 2021-02-05 12:46

Get your application into landscape mode and execute the following code:

UIWindow *toastWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];         


        
4条回答
  •  情书的邮戳
    2021-02-05 13:17

    I believe you have to convert the UICoordinateSpace.

    On iPhone 6 Plus apps can now launch already in landscape orientation, which messed up an application I am working on since it only supports portrait orientation throughout most of the app, except one screen (meaning it needed to support landscape orientations in the plist).

    The code that fixed this was as follows:

    self.window = [[UIWindow alloc] initWithFrame:[self screenBounds]];
    

    and calculating the bounds with the following code:

    - (CGRect)screenBounds
    {
        CGRect bounds = [UIScreen mainScreen].bounds;
        if ([[UIScreen mainScreen] respondsToSelector:@selector(fixedCoordinateSpace)]) {
            id currentCoordSpace = [[UIScreen mainScreen] coordinateSpace];
            id portraitCoordSpace = [[UIScreen mainScreen] fixedCoordinateSpace];
            bounds = [portraitCoordSpace convertRect:[[UIScreen mainScreen] bounds] fromCoordinateSpace:currentCoordSpace];
        }
        return bounds;
    }
    

    Hopefully this will lead you in the right direction.

提交回复
热议问题