我的应用程序处于纵向模式。
当视频播放器进入全屏模式时,我想以横向和纵向播放该视频。
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
[moviePlayer setScalingMode:MPMovieScalingModeFill];
moviePlayer.view.frame = CGRectMake(0, 0, self.videoPlayerView.frame.size.width, self.videoPlayerView.frame.size.height);
[self.videoPlayerView addSubview:moviePlayer.view];
我在一个按钮上播放。
答案 0 :(得分:0)
For you question i would like to give the below Reference
答案 1 :(得分:0)
在部署信息中启用横向设备方向。然后,在ViewController中添加这些方法:
- (BOOL) shouldAutorotate {
return NO;
}
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
答案 2 :(得分:0)
尝试将画布视图作为superview添加到播放器并将转换应用到画布视图。
- (void)initialize{
self.canvas = [[UIView alloc] initWithFrame: self.view.bounds];
[self.view addSubview:self.canvas];
// init moviePlayer
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
...
[self.canvas addSubview: moviePlayer.view];
// Add observers
...
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(deviceOrientationDidChange)
name: UIDeviceOrientationDidChangeNotification
object: nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (void)deviceOrientationDidChange{
// Apply rotation only in full screen mode
if (self.isFullScreen) {
UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;
[UIView animateWithDuration: 0.3
animations: ^{
CGAffineTransform transform = CGAffineTransformMakeRotation(0);
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIDeviceOrientationLandscapeRight:
transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);
break;
default:
break;
};
self.canvas.transform = transform;
self.canvas.frame = self.canvas.superview.bounds;
}];
}
}