Переопределение UITabBarController и UITabBar опускает UITabBar - PullRequest
0 голосов
/ 24 августа 2011

в моем проекте мне пришлось установить фоновое изображение в UITabBar, для чего я переопределяю UITabBar следующим кодом:

@interface UITabBar (CustomImage)
@end
@implementation UITabBar (CustomImage)
  - (void)drawRect:(CGRect)rect {
  UIImage *image = [UIImage imageNamed: @"tab_bg.png"];
  [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  self.backgroundColor = [Constants getNavTintColor];
}
@end

Работало нормально. Мне также нужно было вращать UITabBarController, поэтому я использовал следующий код:

@interface UITabBarController (Autorotate)
@end
@implementation UITabBarController (Autorotate)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   UIViewController *controller = self.selectedViewController;
   if ([controller isKindOfClass:[UINavigationController class]])
       controller = [(UINavigationController *)controller visibleViewController];
   return [controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
@end

После добавления этой части поворота кода работает нормально, но часть UITabBar больше не работает. Что я должен делать? Любая помощь будет оценена.

1 Ответ

0 голосов
/ 24 августа 2011

Вам не нужно реализовывать -shouldAutorotateToInterfaceOrientation: в UITabBarController. Просто внедрите его в каждый из ваших контроллеров представления, и приложение должно вести себя так, как вы ожидаете. (Кроме того, в документации сказано, что у вас не должно быть динамической реализации -shouldAutorotateToInterfaceOrientation.)

...