そこで私は、これを解決するためにviewWillAppearをすくい上げたカテゴリを作成することにしました。
@implementation UIViewController (IsModal)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(viewWillAppear:);
SEL swizzledSelector = @selector(extended_viewWillAppear:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (void)extended_viewWillAppear:(BOOL)animated {
[self extended_viewWillAppear:animated];
[self styleIfModal];
}
- (void)styleIfModal {
if([self isModal] && self.navigationController != nil) {
[self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]];
}
}
- (BOOL)isModal
{
return self.presentingViewController.presentedViewController == self || (self.navigationController != nil && self.navigationController.presentingViewController.presentedViewController == self.navigationController) || [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]];
}
ビューをモーダルに表示してビューを変更し、ビューが正しく終了したときに変更することはできますか? – KrishnaCA
私は、複数のクラスを変更するのではなく、グローバルな解決策を望んでいます。 – puttputt