私は、この問題に対して現在利用可能な最も効率的な解決策を考え出したと信じています。残念ながら、Youtubeビデオプレーヤーはと呼ばれるプライベートクラスのものMPInlineVideoViewController
です。このクラスで外観プロキシを使用することはできません。これはとにかくハックのようなものです。
これが私が思いついたものです。複数の場所で使用できるようにコーディングしました。また、UIWebViewでフォームに入力するときに、戻るUIBarButtonItemsや次のUIBarButtonItemsなどの他の外観プロキシの問題を解決するためにも使用できます。
AppDelegate.h
extern NSString * const ToggleAppearanceStyles;
AppDelegate.m
NSString * const ToggleAppearanceStyles = @"ToggleAppearanceStyles";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSNotification *note = [NSNotification notificationWithName:ToggleAppearanceStyles object:NULL userInfo:@{@"flag" : @(YES)}];
[self toggleAppearanceStyles:note];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleAppearanceStyles:) name:ToggleAppearanceStyles object:NULL];
return YES;
}
-(void)toggleAppearanceStyles:(NSNotification *)note {
UIImage *barButtonBgImage = nil;
UIImage *barButtonBgImageActive = nil;
if([note.userInfo[@"flag"] boolValue]) {
barButtonBgImage = [[UIImage imageNamed:@"g_barbutton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 4, 15, 4)];
barButtonBgImageActive = [[UIImage imageNamed:@"g_barbutton_active.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 4, 15, 4)];
}
[[UIBarButtonItem appearance] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonBgImageActive forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
}
MJWebViewController.m
-(void)viewDidAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:ToggleAppearanceStyles object:NULL userInfo:@{@"flag" : @(NO)}];
[super viewDidAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:ToggleAppearanceStyles object:NULL userInfo:@{@"flag" : @(YES)}];
[super viewWillDisappear:animated];
}
上記のコードでは、外観スタイルをデフォルト値に戻すため、YouTubeプレーヤーが読み込まれると、デフォルトのスタイルが使用されます。現在のViewControllerはすでにロードされているため、スタイル付きの外観になります。
YouTubeプレーヤーを閉じると、現在のViewControllerはリロードされないため、スタイルが維持されます。現在のViewControllerが消えると、スタイル設定された外観が再びオンになります。