开发者

Overriding both UITabBarController & UITabBar omits UITabBar

开发者 https://www.devze.com 2023-03-30 01:57 出处:网络
in my project I had to set background image in UITabBar for that I override UITabBar with the following code:

in my project I had to set background image in UITabBar for that I override UITabBar with the following code:

@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

It worked fine. I also needed the UITabBarController to rotate, so I used the following code:

@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

After adding this code rotation part is working fine but UITabBar part is not working any more. What should I do? Any开发者_JAVA百科 help will be appreciated.


You shouldn't have to implement -shouldAutorotateToInterfaceOrientation: in UITabBarController. Just implement it in each of your view controllers, and the app should behave as you expect. (Plus, the documentation says you shouldn't have a dynamic implementation of -shouldAutorotateToInterfaceOrientation.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号