在我的项目中,我必须在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部分不再工作。我该怎么办?任何帮助都将不胜感激。
发布于 2011-08-24 14:53:10
您不应该非得在UITabBarController中实现-shouldAutorotateToInterfaceOrientation:。只需在每个视图控制器中实现它,应用程序就会按照您的预期运行。(此外,文档还说不应该动态实现-shouldAutorotateToInterfaceOrientation。)
https://stackoverflow.com/questions/7171519
复制相似问题