Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make only a subview landscape?

I know there is a samilar question Only ONE VIEW landscape mode, and I've readed it carefully before I ask this one.

I have a WKWebview named as webview in my app, and the webview have a subview named as player. I used webview to load web page, and player to play a video.

By default the player is compressed at the right-bottom of the webview, and I want to expand player to landscape when I click the expand button for the player.

As the webview and player are defind in WebViewController.swift, that's to say in the same controller. How can I just make the player subview to landscape?

like image 763
LF00 Avatar asked Apr 20 '17 03:04

LF00


3 Answers

You can try with multiple UIWindow. Each UIWindow can have its own root view controller. So it is possible to have one window that rotates, and another one that doesn't. I have used such approach myself and it worked for me very well. It can be very difficult to make your "subview" as independent UIWindow but I think it is worth trying. Hope this information helps.

like image 183
iWheelBuy Avatar answered Nov 19 '22 23:11

iWheelBuy


From my point of view, one can't fix only one orientation for subview in the application. View controller can have only one orientation (landscape/portrait)

You can put dummy video controller to right-bottom in screen and above that, you can put the button or something else (tappable object). When you click on the button or tappable object you can present a new view controller in which you can play video in landscape mode only.

Once video finished playing you can dismiss view controller.

like image 3
Jayeshkumar Sojitra Avatar answered Nov 20 '22 01:11

Jayeshkumar Sojitra


You can check for class when your application received orientation change call like below.

#pragma mark - Orientations Methods
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        if ([[self.window.rootViewController presentedViewController] isKindOfClass:[UINavigationController class]])
        {
            // look for it inside UINavigationController
            UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];

            // is at the top?
            if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]])
            {
                return UIInterfaceOrientationMaskAllButUpsideDown;

                // or it's presented from the top?
            }
            else if ([[nc.topViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
            {
                return UIInterfaceOrientationMaskAllButUpsideDown;
            }
        }
    }

    return UIInterfaceOrientationMaskPortrait;         
}

This method will check that if your class is Movie player then it will allow to rotate your view. You need to handle when user press done button in movie player

like image 2
vivek bhoraniya Avatar answered Nov 20 '22 00:11

vivek bhoraniya