Iphone 在UITabBarController上的选项卡之间共享背景视图
UITabBarController上的选项卡之间是否可以有相同的背景,而不必在所有视图上设置相同的背景?我想在背景中放置一个视图,周期性地执行一个非常短的、非资源密集型的动画。切换选项卡时,我希望该动画保持不变。我已经阅读了UINavigationControllers的操作方法,但还没有找到uitabarcontroller的任何提示。创建一个具有背景的主视图控制器,然后从该控制器添加其他具有透明背景的视图,您还可以将背景放在应用程序窗口中Iphone 在UITabBarController上的选项卡之间共享背景视图,iphone,uiview,uitabbarcontroller,Iphone,Uiview,Uitabbarcontroller,UITabBarController上的选项卡之间是否可以有相同的背景,而不必在所有视图上设置相同的背景?我想在背景中放置一个视图,周期性地执行一个非常短的、非资源密集型的动画。切换选项卡时,我希望该动画保持不变。我已经阅读了UINavigationControllers的操作方法,但还没有找到uitabarcontroller的任何提示。创建一个具有背景的主视图控制器,然后从该控制器添加其他具有透明背景的视图,您还可以将背景放在应用程序窗口中 thierry创建一个具有背景的主视图控制器,然后
thierry创建一个具有背景的主视图控制器,然后从该控制器添加具有透明背景的其他视图,您还可以将背景放在应用程序窗口中
thierry我创建了一个UITabBarController添加类别,允许您执行此操作。请记住,选定的UIViewController需要是透明的,才能看到背景图像 //UITabBarController+CCADTIONS.h
@interface UITabBarController (CCAdditions)
- (void) setBackgroundImage:(UIImage *)i;
@end
//UITabBarController+CCADTIONS.m
#import "UITabBarController+CCAdditions.h"
@implementation UITabBarController (CCAdditions)
- (void) setBackgroundImage:(UIImage *)i {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
imageView.backgroundColor = [UIColor colorWithPatternImage:i];
[[self view] addSubview:imageView];
[[self view] sendSubviewToBack:imageView];
[[self view] setOpaque:NO];
[[self view] setBackgroundColor:[UIColor clearColor]];
[imageView release];
}
@end
//在apdelegate中使用的示例
#import "UITabBarController+CCAdditions.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[tabBarController setBackgroundImage:[UIImage imageNamed:@"icon.png"]];
[tabBarController.view setNeedsDisplay];
return YES;
}
我使用colorWithPatternImage而不是backgroundImage,因为它允许在必要时平铺我创建了一个UITabBarController Additions类别,允许您这样做。请记住,选定的UIViewController需要是透明的,才能看到背景图像 //UITabBarController+CCADTIONS.h
@interface UITabBarController (CCAdditions)
- (void) setBackgroundImage:(UIImage *)i;
@end
//UITabBarController+CCADTIONS.m
#import "UITabBarController+CCAdditions.h"
@implementation UITabBarController (CCAdditions)
- (void) setBackgroundImage:(UIImage *)i {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
imageView.backgroundColor = [UIColor colorWithPatternImage:i];
[[self view] addSubview:imageView];
[[self view] sendSubviewToBack:imageView];
[[self view] setOpaque:NO];
[[self view] setBackgroundColor:[UIColor clearColor]];
[imageView release];
}
@end
//在apdelegate中使用的示例
#import "UITabBarController+CCAdditions.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[tabBarController setBackgroundImage:[UIImage imageNamed:@"icon.png"]];
[tabBarController.view setNeedsDisplay];
return YES;
}
我使用colorWithPatternImage而不是backgroundImage,因为它允许在必要时进行平铺这似乎不适合我。我仍然看到默认的UITabBarController黑色背景。您如何使图像易于访问?因此,您可以轻松地更改它,添加更多的子视图等?据我所知,类别不允许您创建属性。@cannyboy您可以标记UIImageView,或使用关联对象API或子类UIAbbarController将其分配给键。这似乎对我不起作用。我仍然看到默认的UITabBarController黑色背景。您如何使图像易于访问?因此,您可以轻松地更改它,添加更多的子视图等?据我所知,类别不允许您创建属性。@cannyboy您可以标记UIImageView,或使用关联对象API或子类UIAbbarController将其分配给键。