iOS portrait only app returns from UIWebview youtube in landscape

孤街浪徒 提交于 2019-12-10 14:24:57

问题


I'm creating an iOS application and i've encountered the following problem:

The project is set to be a portrait mode application. I have a UIWebview, which loads a webpage with a youtube video in it. When the video is clicked it starts in the youtube player. When the video changes to landscape mode and 'done' is clicked it returns to the UIWebview showing it in landscape.

I do receive a NSNotification when the video is finished but I'm not able to force portrait mode.

This should not be possible, how can I allow youtube to be in landscape but force the app to stay in portrait mode? Or is there another workaround?

EDIT:

After contact with Apple it turned out to be a bug and is reported.


回答1:


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

is private API . I would not recommend using it.

    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIView *view = [window.subviews objectAtIndex:0];
    [view removeFromSuperview];
    [window insertSubview:view atIndex:0];

is much better way i think. It forces the app to adjust its orientation.




回答2:


I think you can use NSNotification as you said and in called method use this line of code for now to force view to portrait

- (void)YourMethodCalledByNSNotification
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    {
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    }
}

Hope that Helps



来源:https://stackoverflow.com/questions/9666877/ios-portrait-only-app-returns-from-uiwebview-youtube-in-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!