MPMoviePlayer全屏播放方向改变

时间:2014-08-18 17:39:36

标签: ios mpmovieplayer orientation-changes

我正在使用viewcontroller开发一个ios应用程序,它有两个子视图A)mpmoviecontroller和B)pageviewcontroller。如果播放器没有处于全屏模式并且我更改了方向子视图对齐是可以的(我处理方向更改并为子视图创建新的CGRects)。当我将视频模式切换到全屏时,旋转到横向并缩小,我的pageviewcontrollers视图已经不在屏幕上了。这是我的代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.streamPlayer.controlStyle = MPMovieControlStyleDefault;

    [self.view addSubview: self.streamPlayer.view];
    [self.streamPlayer prepareToPlay];  
     NSURL *streamURL = [NSURL URLWithString:@"http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"];
    [self.streamPlayer setContentURL:streamURL];
    [self.streamPlayer play];

    self.pageViewController = [self.storyboard          instantiateViewControllerWithIdentifier:@"PageViewController"];

    [self setFramesForPotrait];

    [self addChildViewController:_pageViewController];
    [self.view addSubview:_pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];
}

- (void)orientationChanged:(NSNotification *)notification
{
    [self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        [self setFramesForPotrait];
        NSLog(@"%f",[[UIScreen mainScreen] bounds].size.height);
        NSLog(@"%f",[[UIScreen mainScreen] bounds].size.width);
            }
    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        [self setFramesForLandscapeMode];
//        self.pageViewController.view.frame = self.pageViewContainterRect;
        NSLog(@"%f",[[UIScreen mainScreen] bounds].size.height);
        NSLog(@"%f",[[UIScreen mainScreen] bounds].size.width);
    }
}

-(void)setFramesForPotrait
{
    CGRect frame = [[UIScreen mainScreen] bounds];
    _videoFrameRect  = CGRectMake(0,_BAR_HEIGHT, frame.size.width,_VIDEO_HEIGHT_PORTRAIT);
    _pageViewContainterRect = CGRectMake(frame.origin.x, _BAR_HEIGHT + _VIDEO_HEIGHT_PORTRAIT, frame.size.width, frame.size.height-_BAR_HEIGHT-_VIDEO_HEIGHT_PORTRAIT);

    [self.pageViewController.view setFrame :self.pageViewContainterRect ];
    [self.streamPlayer.view setFrame: _videoFrameRect];
}

-(void)setFramesForLandscaeMode
{
    CGRect frame = [[UIScreen mainScreen] bounds];

    _videoFrameRect = CGRectMake(0,_BAR_HEIGHT, frame.size.height/2,frame.size.width-_BAR_HEIGHT);
    _pageViewContainterRect = CGRectMake(frame.size.height/2, _BAR_HEIGHT, frame.size.height/2,frame.size.width-_BAR_HEIGHT);

    self.pageViewController.view.frame = self.pageViewContainterRect;
    [self.streamPlayer.view setFrame: _videoFrameRect];
}

0 个答案:

没有答案
相关问题