- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有一个支持所有界面方向的 iPhone 应用程序 (iOS6+)。但是,当 MPMoviePlayerController 全屏播放视频时,只应支持横向。
我在 Stack Overflow 上找到了以下解决方案并且它有效。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
...
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.landscapeOnlyOrientation) {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskAll;
}
- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = YES;
}
- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = NO;
}
但是,一个烦人的问题仍然存在,即如果视频以纵向退出全屏(在强制横向播放后),底层 View 不会旋转回来。我必须手动将设备旋转到横向并返回纵向以触发方向更新。有什么方法可以以编程方式触发这种更新吗?
下面的一组截图应该可以说明我的意思:
注意:由于各种原因,无法使用 MPMoviePlayerViewController。
最佳答案
大家好,我遇到了同样的问题,我已经解决了-
这是我的完整代码....
您需要先在 appdelegate 中进行更改:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[[NowPlaying sharedManager] playerViewController] allowRotation])//Place your condition here
{
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
为全屏控制注册通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
然后在播放器 Controller 中添加一行代码:
- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^
{
self.allowRotation = YES;
});
}
- (void)moviePlayerWillExitFullscreenNotification:(NSNotification *)notification
{
self.allowRotation = NO;
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
dispatch_async(dispatch_get_main_queue(), ^
{
//Managing GUI in pause condition
if (self.currentContent.contentType == TypeVideo && self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused)
{
[self.moviePlayerController pause];
if (self.playButton.selected)
self.playButton.selected = NO;
}
self.view.transform = CGAffineTransformMakeRotation(0);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
self.view.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
});
}
此代码在 iOS6 和 iOS7 中测试工作正常。谢谢:)
如果有任何问题,请告诉我......
关于ios - 在全屏模式下强制横向显示 MPMoviePlayerController 会在退出全屏模式时阻止正确的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21911151/
我有这个 MPMovePlayerController 和一个自定义 slider (它不是一个 slider ,但它具有相同的目的)。考虑到我的“ slider ”可以返回我需要的任何浮点值,我怎样
我正在使用 m3u8 视频格式来流式传输视频,现在我需要显示相同的字幕。 我在 Apple 文档中搜索,发现我可以通过使用 closedCaptionDisplayEnabled 来实现这一点。 AV
我正在使用 MPMoviePlayerController 在我的应用程序中播放一个视频。下面是我播放视频的代码。 **NSURL *url=[[NSURL alloc] initFileUR
请检查以下代码: (void) moviePlayerDidExitFullscreen:(NSNotification*)notification { MPMoviePlayerControlle
为了在我的应用中播放视频,我设置了 MPMoviePlayerController并将其添加到 subview 。用户可以使用捏合手势更改为全屏模式。 在此 viewController (包含电影播
有没有捕捉异常的方法(特别是对于网络错误 /没有可用连接)当使用 MPMoviePlayerController 时? 我特别担心一旦播放器的实例被初始化为 initWithURL:您无法知道电影加载
这真让我抓狂。 很简单,我有一个 MPMoviePlayerViewController 并且想要全屏显示电影。 在 iOS 5.0+ 上使用 ARC 我想让这个播放器应用程序范围内可重用。 这部电影
MPMoviePlayerController 似乎存在问题,一旦您处于全屏模式并按住快进按钮,让它向前搜索(以快速播放)一直到视频结尾。 此后,你只会得到一个黑屏,它被卡住了。换句话说,它不响应任何
我正在使用 MPMoviePlayerController 在 iPad 上播放电影。 当用户将设备旋转到横向时,我将其设置为全屏。 如果用户随后点击“退出全屏”或“完成”,电影将动画回到其小帧( n
我正在将应用程序移植到 iOS 8。我有一些代码可以播放以前可以运行的视频,但现在不能了。 当我运行它时,我收到以下错误: ( "", "", "", "", "", "", "", "", "" )
MPMoviePlayerController 支持哪些格式? 最佳答案 根据the documentation : 支持的格式 此类播放 iOS 支持的任何电影或音频文件。这包括流式内容和固定长度文
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
这是代码 - (void)applicationDidFinishLaunching:(UIApplication *)application { NSBundle *bundle = [NSBu
每次我的应用程序更改显示的动画(这是一部循环电影)时,他都会暂停,直到最终开始播放电影。MoviePlayerConntroller 是这样创建的 self.moviePlayer = [MP
MPMoviePlayerController 几乎按照我想要的方式工作,除了它覆盖了屏幕上的任何其他项目,例如我的导航栏。有没有办法阻止这种情况发生? 最佳答案 它的播放器是基于 UIView 的,
我们可以像MPMoviePlayerController中的默认Slider一样制作自定义控件吗用于前进和后退电影? 最佳答案 虽然您无法修改 MPMoviePlayerController 类,但您
我想自定义 MPMoviePlayerController 来为视频播放器添加更多控制。我可以添加额外的控件,但顶部缓冲控件被删除。我怎样才能让它可见? 最佳答案 我对你的问题的理解是你想在 MPMo
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:video_url]
如何调整 MPMoviePlayerController 的帧大小? 最佳答案 通过新版本的 MPMoviePlayerController,您可以做到。 关于iphone - MPMoviePlay
我需要在没有播放器任何覆盖的情况下播放电影。没有播放/停止按钮,没有时间线,没有开始/结束时间,没有进度条,什么都没有。只是 subview 中的普通裸体电影。然后这部电影可能会被我自己的图形覆盖。该
我是一名优秀的程序员,十分优秀!