我正在开发一个不久前为 iOS 4.2 构建的项目。我不得不为 iPhone 5 等调整一些视图的大小。除了缺少背景图像的 NavigationBar 之外,一切都运行良好。
当我尝试在 iOS 6 上编译它时得到的唯一警告是:
@interface UINavigationBar (HomeBrokerNavigationBar)
UIView * topItemHeaderView;
Cannot declare variable inside @interface or @protocol.
我注释掉了那行,并在@interface 上写了同一行,所以现在我没有收到任何编译错误,但 NavigationBar 显示没有图像。
这不是我的项目,所以我不想过多地使用控制器。我只是应该更新视图。有人遇到过这种问题吗?事情是这样的:
UIView * topItemHeaderView;
@interface UINavigationBar (HomeBrokerNavigationBar)
//UIView * topItemHeaderView; //This caused an error so I commented it and placed the line outside.
- (void)layoutNavigationBarBackground;
- (void)layoutNavigationBarShadow;
- (void)setTopItemTitle:(NSString *)title andSubtitle:(NSString *)subtitle;
- (void)setTitleForStockWithShortName:(NSString *)stockShortName andLargeName:(NSString *)stockLargeName;
- (void)setFirstActionButtonWithImage:(NSString *)imageName forTarget:(id)target andAction:(SEL)action;
- (void)setSecondActionButtonWithImage:(NSString *)imageName forTarget:(id)target andAction:(SEL)action;
- (void)setThridActionButtonWithImage:(NSString *)imageName forTarget:(id)target andAction:(SEL)action;
- (void)setActionButtonWithFrame:(CGRect)frame andImage:(NSString *)imageName forTarget:(id)target andAction:(SEL)action;
@end
和 .m 文件:
- (void)drawRect:(CGRect)rect {
self.topItem.hidesBackButton = YES;
if(!self.hidden)
{
self.tintColor = [UIColor colorWithRed:0.003922 green:0.137255 blue:0.313726 alpha:1.0];
[self layoutNavigationBarBackground];
[self layoutNavigationBarShadow];
}
}
- (UIView *)topItemHeaderView {
return topItemHeaderView;
}
- (void)layoutNavigationBarShadow {
CAGradientLayer * navigationBarShadow;
navigationBarShadow = [[CAGradientLayer alloc] init];
navigationBarShadow.frame = CGRectMake(self.frame.origin.x, 0, self.frame.size.width + 20, 20);
CGColorRef topColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5].CGColor;
CGColorRef bottomColor = [self.tintColor colorWithAlphaComponent:0.0].CGColor;
navigationBarShadow.colors = [NSArray arrayWithObjects:(id)topColor, (id)bottomColor, nil];
[navigationBarShadow autorelease];
[self.topItemHeaderView.layer addSublayer:navigationBarShadow];
}
所以它只是 bgHeader.png 没有出现。