为啥 MPMoviePlayerController 全屏按钮图标在 iOS 10 中更改为标题图标?
Posted
技术标签:
【中文标题】为啥 MPMoviePlayerController 全屏按钮图标在 iOS 10 中更改为标题图标?【英文标题】:Why MPMoviePlayerController fullscreen button icon change to caption icon in iOS 10?为什么 MPMoviePlayerController 全屏按钮图标在 iOS 10 中更改为标题图标? 【发布时间】:2016-10-13 04:10:10 【问题描述】:我尝试将 MPMoviePlayerController 用作嵌入式视频播放器,但我发现在 ios 10 中更改了全屏图标的问题?
有没有办法把它改回原来的全屏按钮?
谢谢,
这就是它在 iOS 8 和 iOS 9 中的样子:
这就是它在 iOS 10 中的样子:
【问题讨论】:
你找到解决这个问题的办法了吗? 不,我最终将目标更新到 ios 9 并改用 AVPlayer。 【参考方案1】:这里有一些解决 iOS 10 错误的代码,您可以在 WorkaroundInlinePlayerFullScreenButtonBug.m
文件中编写:
@import MediaPlayer;
@import ObjectiveC;
static void (*configureAuxiliaryButtonsIMP)(id, SEL, BOOL);
static void ConfigureAuxiliaryButtons(id self, SEL _cmd, BOOL flag)
configureAuxiliaryButtonsIMP(self, _cmd, flag);
@try
id delegate = [self delegate]; // Either nil or MPInlineVideoController (responds to `isFullscreen`) or MPInlineVideoFullscreenViewController (does not respond to `isFullscreen`)
BOOL isFullscreen = [delegate respondsToSelector:@selector(isFullscreen)] ? [delegate isFullscreen] : YES;
NSString *imageName = [@[ @"Video", @"Player", @"_", isFullscreen ? @"Exit" : @"Enter", @"Fullscreen" ] componentsJoinedByString:@""];
SEL imageNamedForControlState = NSSelectorFromString([@[ @"_", @"image", @"Named", @":", @"for", @"Control", @"State", @":" ] componentsJoinedByString:@""]);
UIImage *normalImage = ((UIImage *(*)(id, SEL, NSString *, UIControlState))objc_msgSend)(self, imageNamedForControlState, imageName, UIControlStateNormal);
UIImage *highlightedImage = ((UIImage *(*)(id, SEL, NSString *, UIControlState))objc_msgSend)(self, imageNamedForControlState, imageName, UIControlStateHighlighted);
UIButton *fullscreenButton = [self valueForKey:[@[ @"fullscreen", @"Button" ] componentsJoinedByString:@""]];
[fullscreenButton setImage:normalImage forState:UIControlStateNormal];
[fullscreenButton setImage:highlightedImage forState:UIControlStateHighlighted];
@catch (NSException *exception)
NSLog(@"Failed to workaround inline player fullscreen button bug: %@", exception);
void WorkaroundInlinePlayerFullScreenButtonBug(void)
if (![NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)10, 0, 0])
return;
Class MPVideoPlaybackOverlayView = NSClassFromString([@[ @"M", @"P", @"Video", @"Playback", @"Overlay", @"View" ] componentsJoinedByString:@""]);
SEL configureAuxiliaryButtonsSEL = NSSelectorFromString([@[ @"_", @"configure", @"Auxiliary", @"Buttons", @":" ] componentsJoinedByString:@""]);
NSMethodSignature *methodSignature = [MPVideoPlaybackOverlayView instanceMethodSignatureForSelector:configureAuxiliaryButtonsSEL];
if (methodSignature.numberOfArguments != 3)
NSLog(@"Failed to workaround inline player fullscreen button bug (method not found)");
return;
const char *returnType = methodSignature.methodReturnType;
const char *argType = [methodSignature getArgumentTypeAtIndex:2];
if (strcmp(returnType, @encode(void)) != 0 || strcmp(argType, @encode(BOOL)) != 0)
NSLog(@"Failed to workaround inline player fullscreen button bug (type mismatch)");
return;
Method configureAuxiliaryButtons = class_getInstanceMethod(MPVideoPlaybackOverlayView, configureAuxiliaryButtonsSEL);
configureAuxiliaryButtonsIMP = (__typeof__(configureAuxiliaryButtonsIMP))method_getImplementation(configureAuxiliaryButtons);
method_setImplementation(configureAuxiliaryButtons, (IMP)ConfigureAuxiliaryButtons);
然后更新您的main.m
文件以在运行UIApplicationMain
函数之前调用WorkaroundInlinePlayerFullScreenButtonBug
函数:
#import "AppDelegate.h"
extern void WorkaroundInlinePlayerFullScreenButtonBug(void);
int main(int argc, char *argv[])
@autoreleasepool
WorkaroundInlinePlayerFullScreenButtonBug();
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
【讨论】:
你能告诉我如何在没有 main.m 文件的 Swift 项目中实现这个解决方案吗?我的图标也有同样的问题,而你的问题是我找到的唯一解决方案。 Apple 是否会通过此更改批准我的应用程序?以上是关于为啥 MPMoviePlayerController 全屏按钮图标在 iOS 10 中更改为标题图标?的主要内容,如果未能解决你的问题,请参考以下文章
为啥使用 glTranslatef?为啥不直接更改渲染坐标?
为啥 DataGridView 上的 DoubleBuffered 属性默认为 false,为啥它受到保护?