how to make only a subview landscape?
Asked Answered
T

3

5

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?

Tommyetommyrot answered 20/4, 2017 at 3:2 Comment(1)
#24928557Tommyetommyrot
T
6

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.

Tegument answered 29/4, 2017 at 10:47 Comment(0)
E
3

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.

Euphony answered 29/4, 2017 at 6:58 Comment(0)
C
2

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

Concourse answered 5/5, 2017 at 5:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.