Play video fullscreen in landscape mode, when my e

2019-02-10 05:03发布

I want to play video in landscape mode in fullscreen. And my application is lock in portrait mode. How to implement this. Please help me. Thanks in advance

4条回答
ゆ 、 Hurt°
2楼-- · 2019-02-10 05:11

I've done this in on of my app. To do this you need to check that is your viewcontroller that where you want to play a video.

  • The first thing you have to do is check Device Orientation to Portrait,Landscape left, Landscape right in your project target

  • In your AppDelegate do the below code

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    
        UIStoryboard *mainStoryboard;
        if (IS_IPHONE) {
            mainStoryboard= [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        }
        else{
           mainStoryboard= [UIStoryboard storyboardWithName:@"Main_iPad" bundle: nil];
        }
    
        ViewControllerThatPlaysVideo *currentViewController=    ViewControllerThatPlaysVideo*)[mainStoryboard     instantiateViewControllerWithIdentifier:@"postDetailView"];
        if(navigationController.visibleViewController isKindOfClass:    [ViewControllerThatPlaysVideo class]]){
           if([currentViewController playerState])
                return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait;
           return UIInterfaceOrientationMaskPortrait;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    
查看更多
对你真心纯属浪费
3楼-- · 2019-02-10 05:12

Simplest solution in swift 3 Add this to your app delegate:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if window == self.window {
        return .portrait
    } else {
        return .allButUpsideDown
    }
}
查看更多
爷的心禁止访问
4楼-- · 2019-02-10 05:13
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

Just call it in - viewDidAppear: of the presented view controller.

Another way :

First, you have to understand that in order to open even just one view out of over 100 in landscape, your app should allow both landscape and portrait interface orientations. It is the case by default, but you can check it in your target's settings, General tab, Deployment Info section

Then, because you allowed both landscape and portrait for the entire app, you will have to tell every portrait-only UIViewController that it should not autorotate, adding this method's implementation:-

- (BOOL)shouldAutorotate {
    return NO;
}

Finally, for your specific landscape-only controller, and because you said you are presenting it modally, you can just implement these methods:-

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft; // or Right of course
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

Hope this will help :)

查看更多
走好不送
5楼-- · 2019-02-10 05:31

After staring at this page for almost an entire day, I finally figured out a working time saving solution for all,

Go to the project navigator, select your project and in General select just potrait in device orientation.

Also make sure that you're using a modal segue to show the landscapeController.

Now add this in your controller where in you want the landscape mode.

override func viewWillAppear(_ animated: Bool) {

    super.viewWillAppear(true)
}

override var shouldAutorotate: Bool {

    return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {

    return .landscapeRight
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {

    return .landscapeRight
}

And that's it folks.

查看更多
登录 后发表回答