简体   繁体   中英

MPMediaPlayer becomes small when i rotate it in ios 8

I have application which plays video. It was great and good working in ios7 but now in iOs8 it is broken

self.player = [[MPMoviePlayerController alloc] initWithContentURL:self.videoFileToDisplay];
[self.player play];

[self.view setBackgroundColor:[UIColor redColor]];
[self.player.view setBackgroundColor:[UIColor greenColor]];
UIView *playerView = self.player.view;

[self.view addSubview:playerView];
playerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[playerView]|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:NSDictionaryOfVariableBindings(playerView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[playerView]|"
                                                                  options:0
                                                                  metrics:nil

Also depending on horizontal or vertical video it is i need to rotate it

- (void)adoptVideoToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation withDuration:(NSTimeInterval)duration
{

    CGFloat horizontalVideoAngle = 0;
    CGFloat verticalVideoAngle = 0;

    switch (toInterfaceOrientation) {
        case UIDeviceOrientationLandscapeLeft:
            horizontalVideoAngle = 0;
            verticalVideoAngle = M_PI_2;
            break;
        case UIDeviceOrientationLandscapeRight:
            horizontalVideoAngle = 0;
            verticalVideoAngle = -M_PI_2;
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            verticalVideoAngle = 0;
            horizontalVideoAngle = M_PI_2;
            break;
        case UIDeviceOrientationPortrait:
            verticalVideoAngle = 0;
            horizontalVideoAngle = -M_PI_2;
            break;
        default:
            return;
    }

    CGFloat angle = [self isHorizontalVideo] ? horizontalVideoAngle : verticalVideoAngle;
    self.player.view.transform = CGAffineTransformMakeRotation( angle );
}

It is good at all orientations except portrait. Even UpsideDown is good Here are screenshots

肖像景观权上下翻转景观左

What is wrong with portrait orientation in ios8 ?

PS red view is background of mediaPlayer superview

Looks like Apple changed rotation in ios8 now it rotates content only and doesn't affect view frame. So i ended up adding additional scale transform

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM