显示性能问题的标签栏

Posted

技术标签:

【中文标题】显示性能问题的标签栏【英文标题】:tab bar presenting performance issue 【发布时间】:2011-10-10 09:20:21 【问题描述】:

我有一个视图控制器,其中包含一些自定义按钮,单击按钮后,我将呈现不同的视图。单击其中一个按钮,我将呈现带有导航控制器的标签栏控制器。

代码如下

TabBarView *tabbar=[[TabBarView alloc]init];
        UINavigationController *navNextController       = [[UINavigationController alloc] initWithRootViewController:tabbar];
        [self presentModalViewController:navNextController animated:YES];

标签栏代码如下

UINavigationController *localNavigationController;
tabbarcontroller = [[UITabBarController alloc] init];

localControllersArray = [[NSMutableArray alloc] initWithCapacity:3];
tabbarcontroller.delegate=self;


ShoppingListView *shop;
shop = [[ShoppingListView alloc] init];
shop.parentVC=self;
localNavigationController = [[UINavigationController alloc] initWithRootViewController:shop];
[localNavigationController.tabBarItem setTitle:@"Lists"];
[localNavigationController.tabBarItem setImage:[UIImage imageWithContentsOfFile:[IMBundle fullBundlePath:@"Images.bundle/Images/EnhancedMobileLists/list.png"]]];   
[localNavigationController viewWillAppear:YES];
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[shop release];

FavoritesViewController *fav;
fav = [[FavoritesViewController alloc] init];
fav.parentVC=self;
localNavigationController = [[UINavigationController alloc] initWithRootViewController:fav];
[localNavigationController.tabBarItem setTitle:@"Favorites" ];
[localNavigationController.tabBarItem setImage:[UIImage imageWithContentsOfFile:[IMBundle fullBundlePath:@"Images.bundle/Images/EnhancedMobileLists/favorites.png"]]];  
[localNavigationController viewWillAppear:YES];
[localNavigationController viewWillDisappear:YES];
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[fav release];

ShareListViewController *share;
share = [[ShareListViewController alloc] init];
share.parentVC=self;
localNavigationController = [[UINavigationController alloc] initWithRootViewController:share];
[localNavigationController.tabBarItem setTitle:@"Share" ];
[localNavigationController.tabBarItem setImage:[UIImage imageWithContentsOfFile:[IMBundle fullBundlePath:@"Images.bundle/Images/EnhancedMobileLists/share.png"]]];  
[localNavigationController viewWillAppear:YES];

[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[share release];

tabbarcontroller.viewControllers = localControllersArray;
[self.view addSubview:tabbarcontroller.view];

主要问题是在单击按钮以显示标签栏视图时,它需要一些时间来加载,即有一段时间它看起来好像视图被挂起,而我正在另一个按钮中显示导航视图,它可以正常工作出任耽误。请告诉我我的代码有什么问题以及如何纠正在 iphone 中单击 uibutton 时显示标签栏的延迟。

提前致谢

【问题讨论】:

【参考方案1】:

下面的代码被写入Appdelegate文件,然后当点击这个方法被调用的按钮时,这个方法在按钮上被调用。

-(void)ShowTabAbout [viewController.view removeFromSuperview]; self.imgV.frame=CGRectMake(0, 425, 320, 55); self.imgV.image=[UIImage imageNamed:@"tBar5.png"]; [self.tabctr.view addSubview:self.imgV]; self.tabctr.selectedIndex=4; // [自己 动画标签代码]; [窗口addSubview:tabctr.view];

 

以下动画代码用于导航视图控制器。

-(void)animationTabBarCode

 tr.type=kCATransitionPush;
 tr.subtype=kCATransitionFromRight;


 tr.delegate=self;    

[self.window.layer addAnimation:tr forKey:nil];

以下代码被植入到位于视图控制器方法文件的按钮中。

-(IBAction)btnTapped:(id)sender

[appDelegate ShowTabAbout];

 [appDelegate animationTabBarCode];  

【讨论】:

有关自定义标签栏的更多详细信息,请点击参考链接参考sugartin.info/2011/07/01/customizing-tab-bar

以上是关于显示性能问题的标签栏的主要内容,如果未能解决你的问题,请参考以下文章

电脑明明有内存,却总是显示内存不足,是怎么回事?

Yslow

html标签上的多个类总是会影响渲染性能吗?

虚拟内存怎么设置?

电脑如何设置虚拟内存?

重新安装与设置显示之间的性能和内存差异=“无”