iOS-仅在视频上允许横向模式 [英] iOS - Allow Landscape mode on videos only
问题描述
我的整个应用中都有视频.一些使用MPMoviePlayerController,其他使用带有YouTube的UIWebView.我希望我的应用程序完全是纵向的.但是,我想让用户可以选择在有视频时翻转到风景(不是强制,而是可选).
I have videos throughout my app. Some using MPMoviePlayerController, others in a UIWebView with YouTube. I want my app to be totally portrait. However, I want to give the user the option to flip to landscape when there's a video (not force, but optional).
我一直在网上寻找答案,但是还没有发现任何东西.
I've been searching the web for an answer, but I haven't found anything yet.
感谢您的帮助!
推荐答案
我遇到了相同的问题,并通过在我的应用程序委托中添加了此问题进行了修复,基本上只允许在MPMoviePlayerViewController的子类上进行横向定向:
I had the same issue and fixed it by adding this in my app delegate, basically allowing Landscape orientation only on subclasses of MPMoviePlayerViewController:
#import <MediaPlayer/MediaPlayer.h>
@implementation UIViewController (orientationFix)
-(NSUInteger) supportedInterfaceOrientations
{
if ([[self class] isSubclassOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([[self class] isSubclassOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
return UIInterfaceOrientationPortrait;
}
@end
@implementation MyAppDelegate
.
.
.
@end
这篇关于iOS-仅在视频上允许横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!