xcode 6 个自定义选项卡栏在选择图像之前不显示图像
xcode 6 custom tab bar not showing images until they are selected
我几年前写的几个应用程序都在商店里,一切正常,工作正常,已批准等。
我现在已经在 Xcode 6 中打开它们来对它们进行一些更新,我编写的自定义选项卡栏在 Xcode 4 中运行良好,现在显示出非常奇怪的行为。
该栏在第一次加载时显示为空白,但当每个选项卡都是 touched/selected 时,图像就会加载。一旦所有选项卡都被选中一次,该栏就会完全正常工作并且所有图像都按预期显示 - 但在第一次加载时,选项卡栏显示空白(第一个选项卡除外,因为它已被选中)。
代码自从它以前工作以来没有改变,所有图像都在那里并且加载正常,因为一旦选择了一个选项卡,它们就会正常显示。只有在第一次加载时才会显示图像,直到触摸并选择该选项卡。
我的这个自定义标签栏的代码如下,以前一切正常,现在在商店的应用程序中也能正常工作:
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGRect tabbarTopFrame = CGRectMake(0,(screenSize.height - 59),320,10);
UIImageView *tabbarTop = [[UIImageView alloc] initWithFrame:tabbarTopFrame];
tabbarTop.image = [UIImage imageNamed:@"tabbar_top.png"];
[self.tabBarController.view addSubview:tabbarTop];
UIImage *selectedImage0 = [UIImage imageNamed:@"tabbar_introduction_active.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tabbar_introduction_default.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"tabbar_nests_active.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tabbar_nests_default.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"tabbar_home_active.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tabbar_home_default.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_active.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_default.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"tabbar_spotted_active.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"tabbar_spotted_default.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];
item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
关于上述代码,自 Xcode 4 以来发生了哪些变化,或者上述代码是否存在任何问题,导致图像在被选中之前无法加载?
Xcode 显示代码没有错误或警告。
这让我悲痛欲绝,我无法理解这种行为!
尝试检查 unselectedimages 是否在文件夹中。尝试再次删除并重新连接此图像,并确保将它们添加到目标。
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
该函数首先在 iOS7 中弃用。
备选方案:
[item0 setImage:[unselectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item0 setSelectedImage:[selectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
我几年前写的几个应用程序都在商店里,一切正常,工作正常,已批准等。
我现在已经在 Xcode 6 中打开它们来对它们进行一些更新,我编写的自定义选项卡栏在 Xcode 4 中运行良好,现在显示出非常奇怪的行为。
该栏在第一次加载时显示为空白,但当每个选项卡都是 touched/selected 时,图像就会加载。一旦所有选项卡都被选中一次,该栏就会完全正常工作并且所有图像都按预期显示 - 但在第一次加载时,选项卡栏显示空白(第一个选项卡除外,因为它已被选中)。
代码自从它以前工作以来没有改变,所有图像都在那里并且加载正常,因为一旦选择了一个选项卡,它们就会正常显示。只有在第一次加载时才会显示图像,直到触摸并选择该选项卡。
我的这个自定义标签栏的代码如下,以前一切正常,现在在商店的应用程序中也能正常工作:
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGRect tabbarTopFrame = CGRectMake(0,(screenSize.height - 59),320,10);
UIImageView *tabbarTop = [[UIImageView alloc] initWithFrame:tabbarTopFrame];
tabbarTop.image = [UIImage imageNamed:@"tabbar_top.png"];
[self.tabBarController.view addSubview:tabbarTop];
UIImage *selectedImage0 = [UIImage imageNamed:@"tabbar_introduction_active.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tabbar_introduction_default.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"tabbar_nests_active.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tabbar_nests_default.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"tabbar_home_active.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tabbar_home_default.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_active.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_default.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"tabbar_spotted_active.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"tabbar_spotted_default.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];
item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
关于上述代码,自 Xcode 4 以来发生了哪些变化,或者上述代码是否存在任何问题,导致图像在被选中之前无法加载?
Xcode 显示代码没有错误或警告。
这让我悲痛欲绝,我无法理解这种行为!
尝试检查 unselectedimages 是否在文件夹中。尝试再次删除并重新连接此图像,并确保将它们添加到目标。
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
该函数首先在 iOS7 中弃用。
备选方案:
[item0 setImage:[unselectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item0 setSelectedImage:[selectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];