iOS - Video not rotating only in iOS7 over iPhone?

喜欢而已 提交于 2019-12-09 08:12:21

问题


What i have Done?

I am playing videos in an extended class of MPMoviePlayerViewController and have implemented orientation functions as follows

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        return FALSE;
    }
    else{
        return TRUE;
    }
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self setControlsPositions:toInterfaceOrientation];
}
-(BOOL)shouldAutorotate
{
    return YES;
}

What issue i am Facing?

The application works fine up till iOS6 on Both iPhone and iPad Almong with iPad (with iOS7) but the video does not rotate over iPhone with iOS7 installed.

What is the reason for such issue and how it can be resolved?

Update

I have found that the video does rotates if setMovieSourceType is set to MPMovieSourceTypeUnknown but does not rotate when set to `MPMovieSourceTypeStreaming


回答1:


After apple wanted me to give them a sample for the bug reported by me in iOS-7 i found that i wasn't pushing the view Controller rather i was adding the view to window. In such cases other view Controllers do get the orientation events but the MPMoviePlayerViewController subclass didn't so i just presentated the view controller instead of adding the its view and it worked.




回答2:


Try this solution:

At your AppDelegate.h:

@property  (nonatomic, assign) BOOL *fullScreenVideoIsPlaying;

At your AppDelegate.m:

@synthesize fullScreenVideoIsPlaying;

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
    if (self.fullScreenVideoIsPlaying) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        if(self.window.rootViewController){
            UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
            orientations = [presentedViewController supportedInterfaceOrientations];
        }
        return orientations;
    }}

At your ViewController:

in the viewDidLoad Method:

    myDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];

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

And add those two methods in the same class:

-(void) movieStarted:(NSNotification*) notif {
     myDelegate.fullScreenVideoIsPlaying = YES;
}
-(void) youTubeFinished:(movieFinished*) notif {
     myDelegate.fullScreenVideoIsPlaying = NO;
}



回答3:


The rotation methods changed with iOS 6 you will need to add the iOS 6 rotate methods to your view controller:

- (BOOL)shouldAutorotate {
    return YES:
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

And you need to add Supported interface orientations with the supported orientations to your apps info.plist.

From the iOS 6.0 release information:

The UIViewController class has new interfaces supporting the following behaviors:

  • New interfaces provide a clearer path for managing and tracking interface rotations.



回答4:


i think device rotation is locked in the control centre cause it running fine in ipad ios 7.



来源:https://stackoverflow.com/questions/19093991/ios-video-not-rotating-only-in-ios7-over-iphone

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