播放视频时如何旋转屏幕?

时间:2014-11-11 21:38:57

标签: ios objective-c xcode rotation ios8

我在播放来自webview的视频时用于旋转屏幕的代码在iOS 8中不再有效,是否有其他方法可以在iOS 8中执行此操作?

更新

我现在正在使用此代码

#define IS_OS_6_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define IS_OS_8_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

if(IS_OS_6_OR_LATER){

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];

}

if (IS_OS_8_OR_LATER) {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:UIWindowDidBecomeVisibleNotification object:self.view.window];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:UIWindowDidBecomeHiddenNotification object:self.view.window];

}
ios 7中的

我使用了这个

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];

-(void)youTubeStarted{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.fullScreenVideoIsPlaying = YES;
}

-(void)youTubeFinished{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.fullScreenVideoIsPlaying = NO;
}

但他们都没有工作

1 个答案:

答案 0 :(得分:0)

NSString *currSysVer = [[UIDevice currentDevice] systemVersion];    
NSString *reqSysVer8 = @"8.0";
if ([currSysVer compare:reqSysVer8 options:NSNumericSearch] != NSOrderedAscending) {
    //iOS8.0 or greater (bounds ARE orientation dependant)
    if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
        NSLog(@"Launch orientation >iOS8 portrait - INVERSING");
        //portrait, inverse dimensions
        _screenFrame.size.width = bounds.size.height;
        _screenFrame.size.height = bounds.size.width;
    }
    else {
        _screenFrame = [[UIScreen mainScreen] bounds];
    }