【发布时间】:2014-09-26 07:58:32
【问题描述】:
我想使用 UIVIsualEffectView 给导航栏添加模糊效果。我有如下自定义导航栏类。
头文件
#import <UIKit/UIKit.h>
@interface GSNavigationBar : UINavigationBar
@end
实现文件如下所示
#import "GSNavigationBar.h"
@implementation GSNavigationBar
- (void) awakeFromNib {
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
visualEffectView.frame = CGRectMake(0, -21, self.frame.size.width , self.frame.size.height + 21);
[self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self insertSubview:visualEffectView atIndex:1000];
}
@end
通过上面的代码,我可以实现导航栏的模糊效果。在推动视图控制器时(通过使用“Push”segue),导航栏中的左栏按钮项和右栏项变为非活动状态。为了更清楚,我附上了视图控制器的屏幕截图。
This is view controller #1. All navigation item buttons are clickable
This is view controller #2. We land up here due to push segue from view controller #1. Navigation item buttons are NOT clickable. Also the title goes missing. I had set the title using self.title
【问题讨论】:
-
为什么要在导航栏添加一个空图像?导航栏已经有模糊效果,你应该使用它。
标签: ios objective-c