【发布时间】:2013-09-13 12:07:34
【问题描述】:
在 iOs7 下,而不是早期版本,我有一条线穿过我的标签栏(在下面链接的示例图片中显示为绿色箭头)。
我不知道问题出在哪里。知道如何纠正它吗?
非常感谢。
【问题讨论】:
标签: uitabbarcontroller ios7 uitabbar uitabbaritem
在 iOs7 下,而不是早期版本,我有一条线穿过我的标签栏(在下面链接的示例图片中显示为绿色箭头)。
我不知道问题出在哪里。知道如何纠正它吗?
非常感谢。
【问题讨论】:
标签: uitabbarcontroller ios7 uitabbar uitabbaritem
如果您指的是条形顶部的一对像素阴影,则很容易将其移除。您所要做的就是在标签栏上启用 clipsToBounds,如下所示:
[self.tabBarController.tabBar setClipsToBounds:YES];
【讨论】:
在创建 TabBar 后添加这两行
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
【讨论】:
UIImage* tabBarBackground = [UIImage imageNamed:@"transparentImage.png"];
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
/////transparentImage.png - 空的 1x1px 图像 //// 解决了我的问题
【讨论】:
我认为您必须检查 iOS 7 中 UITabBar 的高度。Apple 可能降低了 UITabBar 的高度,根据 UITabBar 的高度您必须重新设计图像以获得准确的结果。
【讨论】:
使用这个 [[UITabBar 外观] setShadowImage:[UIImage imageNamed:@"transparentImage.png"]];
transparentImage.png 可以是 0 alpha 大小 1x1 像素的图像
【讨论】:
如果您在使用高于 UITabBar 高度的自定义 UITabBarItem 时遇到困难,可以使用 CALayer 实现一个解决方案,让您保留默认的 UITabBar shadowImage 和 backgroundImage(具有模糊效果)。
我在我的 UITabBarController 子类中使用此代码:
- (id) init
{
if ((self = [super init]))
{
self.delegate = self;
CALayer * superLayer = self.tabBar.layer;
CALayer * layer = [CALayer layer];
layer.bounds = CGRectMake (0.0f, 0.0f, 62.0f, 56.0f);
layer.contents = (id) [UIImage imageNamed: @"custom-tabbaritem"].CGImage;
layer.anchorPoint = CGPointMake (0.5f, 1.0f);
layer.position = CGPointMake (superLayer.bounds.size.width / 2.0f, superLayer.bounds.size.height);
layer.zPosition = 1.0f;
[self.tabBar.layer addSublayer: layer];
}
return self;
}
请注意,您也可以使用layer.frame = CGRectMake (...) 代替bounds、anchorPoint 和position。通过将子层锚定到UITabBar 的底部,我正在使用这些来更好地处理各种高度的图像。
通过实现诸如tabBarController:shouldSelectViewController: 之类的UITabBarControllerDelegate 方法,可以使UITabBarItem 执行自定义操作,例如呈现模态视图控制器。
在这种情况下,我使用普通的UIViewController 作为自定义UITabBarItem 的视图控制器(其他都是子类):
- (BOOL) tabBarController: (UITabBarController *) tabBarController
shouldSelectViewController: (UIViewController *) viewController
{
if ([viewController isMemberOfClass: [UIViewController class]])
{
SomeViewController * modal = [SomeViewController new];
[tabBarController presentViewController: modal
animated: YES
completion: nil];
modal = nil;
return NO;
}
return YES;
}
【讨论】: