Jos*_*iel 5 cocoa-touch objective-c mpmovieplayercontroller ios
我在detailView(UIVIew)中创建了一个MPMoviePlayerController,现在我想在用户点击FullScreen按钮时强制MPMoviePlayerController进行横向视图.我能这样做吗?请给我任何建议.在此先感谢.这是我创建的代码:
NSURL *movieURL = [NSURL URLWithString:previewString];
movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
movieController.view.backgroundColor = [UIColor grayColor];
[detailview addSubview:movieController.view];
[movieController prepareToPlay];
movieController.shouldAutoplay = NO;
Run Code Online (Sandbox Code Playgroud)
和willEnterFullscreen()函数:
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(@"willEnterFullscreen");
donepress = YES;
// nothing
}
Run Code Online (Sandbox Code Playgroud)
我试过搜索但仍然没有任何好的答案.请帮我.非常感谢
小智 12
是的,您可以使用两个通知观察者来更改完整方向.
首先,在AppDelegate didFinishLaunchingWithOptions方法中添加两个通知观察器:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
第二,添加方法和属性
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.allowRotation = NO;
}
Run Code Online (Sandbox Code Playgroud)
第三,覆盖supportedInterfaceOrientationsForWindow方法,您可以返回所需的任何方向
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3403 次 |
| 最近记录: |