【发布时间】:2011-08-24 06:49:23
【问题描述】:
在我的项目中,我必须在 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 部分不再工作。我该怎么办?任何帮助将不胜感激。
【问题讨论】:
标签: iphone objective-c uitabbarcontroller overriding uitabbar