在本文中,我们将详细介绍为iOS7半透明UINavigationBar实现明亮、生动的色彩的各个方面,并为您提供关于iphone半透明图标的相关解答,同时,我们也将为您带来关于IOSnavigatio
在本文中,我们将详细介绍为 iOS 7 半透明 UINavigationBar 实现明亮、生动的色彩的各个方面,并为您提供关于iphone半透明图标的相关解答,同时,我们也将为您带来关于IOS navigationbar 透明问题 -求解决方法、iOS UINavigationBar vs UIToolbar vs UITabBar、iOS UINavigationBar的工具类问题、ios – UINavigationBar -pushNavigationItem在将新控制器推送到UINavigationController堆栈时从不调用的有用知识。
本文目录一览:- 为 iOS 7 半透明 UINavigationBar 实现明亮、生动的色彩(iphone半透明图标)
- IOS navigationbar 透明问题 -求解决方法
- iOS UINavigationBar vs UIToolbar vs UITabBar
- iOS UINavigationBar的工具类问题
- ios – UINavigationBar -pushNavigationItem在将新控制器推送到UINavigationController堆栈时从不调用
为 iOS 7 半透明 UINavigationBar 实现明亮、生动的色彩(iphone半透明图标)
iOS 7.1 更新:在此更新中,修改 UINavigationBar 中的 alpha 通道的解决方法似乎已被忽略。现在,最好的解决方案似乎是“处理它”,并希望你选择的任何颜色都能呈现半透明的效果。我仍在寻找解决此问题的方法。
iOS 7.0.3 更新:我们创建的 GitHub 库已经更新,可以在使用 iOS 7.0.3 时稍微解决这个问题。不幸的是,没有神奇的公式来支持在 iOS 7.0.2 及更早版本和 iOS 7.0.3 中创建的两种颜色。似乎Apple提高了饱和度,但以不透明度为代价(因为模糊的半透明取决于不透明度级别)。我和其他一些人正在努力为此创建一个更好的解决方案。
我相信很多人已经遇到过这样的问题:iOS 7 倾向于降低半透明 UINavigationBar 的颜色饱和度。
我的目标是实现一个具有这种色调但半透明的 UINavigationBar:
但是,通过半透明,我得到了这个。背景视图是白色的,我知道这会使这个视图更亮一点:
有没有办法在保持半透明的同时达到原始颜色?我注意到 Facebook 已经能够让他们的栏变成丰富的蓝色,如下所示:
..所以我知道必须有某种方式。背景视图显然在这里有所作为,但它们的大部分内容也是灰色/白色的。似乎无论您输入哪种条形色调颜色,您都无法在半透明下获得鲜艳的色彩。
更新了解决方案。
这是我最终提出的解决方案。我采用了aprato的解决方案,然后将自定义包含UINavigationBar
在一个UINavigationController
子类中。我创建了一个存储库,该存储库具有下面列出的此实现以及示例应用程序。
////////////////////////////// CRNavigationBar.m////////////////////////////#import "CRNavigationBar.h"@interface CRNavigationBar ()@property (nonatomic, strong) CALayer *colorLayer;@end@implementation CRNavigationBarstatic CGFloat const kDefaultColorLayerOpacity = 0.5f;static CGFloat const kSpaceToCoverStatusBars = 20.0f;- (void)setBarTintColor:(UIColor *)barTintColor { [super setBarTintColor:barTintColor]; if (self.colorLayer == nil) { self.colorLayer = [CALayer layer]; self.colorLayer.opacity = kDefaultColorLayerOpacity; [self.layer addSublayer:self.colorLayer]; } self.colorLayer.backgroundColor = barTintColor.CGColor;}- (void)layoutSubviews { [super layoutSubviews]; if (self.colorLayer != nil) { self.colorLayer.frame = CGRectMake(0, 0 - kSpaceToCoverStatusBars, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + kSpaceToCoverStatusBars); [self.layer insertSublayer:self.colorLayer atIndex:1]; }}@end
////////////////////////////// CRNavigationController.m////////////////////////////#import "CRNavigationController.h"#import "CRNavigationBar.h"@interface CRNavigationController ()@end@implementation CRNavigationController- (id)init { self = [super initWithNavigationBarClass:[CRNavigationBar class] toolbarClass:nil]; if(self) { // Custom initialization here, if needed. } return self;}- (id)initWithRootViewController:(UIViewController *)rootViewController { self = [super initWithNavigationBarClass:[CRNavigationBar class] toolbarClass:nil]; if(self) { self.viewControllers = @[rootViewController]; } return self;}@end
答案1
小编典典iOS 7.0.3 更新:正如你在上面看到的 7.0.3 改变了一些事情。我已经更新了我的要点。希望随着人们的升级,这种情况会消失。
原始答案: 我最终得到了一个结合其他两个答案的黑客。我将 UINavigationBar 子类化并在后面添加一个图层,如果各种高度状态栏中的任何一个处于上升状态,则可以使用一些额外的空间来覆盖。图层在布局子视图中进行调整,并且每当您设置 barTintColor 时颜色都会发生变化。
要点:https ://gist.github.com/aprato/6631390
setBarTintColor
[super setBarTintColor:barTintColor]; if (self.extraColorLayer == nil) { self.extraColorLayer = [CALayer layer]; self.extraColorLayer.opacity = self.extraColorLayerOpacity; [self.layer addSublayer:self.extraColorLayer]; } self.extraColorLayer.backgroundColor = barTintColor.CGColor;
布局子视图
[super layoutSubviews]; if (self.extraColorLayer != nil) { [self.extraColorLayer removeFromSuperlayer]; self.extraColorLayer.opacity = self.extraColorLayerOpacity; [self.layer insertSublayer:self.extraColorLayer atIndex:1]; CGFloat spaceAboveBar = self.frame.origin.y; self.extraColorLayer.frame = CGRectMake(0, 0 - spaceAboveBar, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + spaceAboveBar); }
IOS navigationbar 透明问题 -求解决方法
最近被一个IOS navigationBar 的问题困扰了。。
A页面的navigationbar背景颜色是[UIColor clear],也就是透明。
B页面的navigationbar背景颜色是[UIColor blue],
A页面使用push打开B页面,navigationbar 会先显示B页面navigationbar设置的颜色,
同理,B页面pop的时候,navigationbar 会先显示A页面navigationbar设置透明颜色。
以至于出现了图片中的效果。。动画过程中有一个黑块。。
请问下,各位童鞋们,是否遇到这种情况,怎么解决呢。。。感谢。。。。
iOS UINavigationBar vs UIToolbar vs UITabBar
他们之间有什么区别?
每个组件的优点和缺点是什么?
解决方法
UIToolbar类的一个实例是用于选择许多按钮之一的控件,称为工具栏项。点击时,工具栏会突出显示或不更改项目的外观。如果您需要单选按钮样式控件,请使用UITabBar类。
UITabBar类实现一个控件,用于选择两个或更多个按钮之一,称为项目。标签栏最常见的用法是实现一个模式界面,其中轻击项目会更改选择。
iOS UINavigationBar的工具类问题
想写一个UINavigationBar的工具类,在加上UIBarButtonItem点击事件方法时会报错:*** Terminating app due to uncaught exception ''NSInvalidArgumentException'', reason: ''-[OfflineHistoryViewController backButtonHandler]: unrecognized selector sent to instance 0x7f81e3183440''
请问问题出在哪里?
这个工具类需要传一个ViewController,来执行dismissViewControllerAnimated:YES completion:^{}方法,而我在具体的ViewController中初始化这个工具类的时候传的是self.
代码如下:
1. 工具类.h
// // TitleBarHelper.h // #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> @interface TitleBarHelper : NSObject { } @property(nonatomic, retain) UIViewController *viewController; @property(nonatomic, retain) NSString *titleStr; @property(nonatomic) BOOL needBack; - (id)initWithTitle:(NSString *)title ViewController:(UIViewController *)controller needBack:(BOOL)needBack; - (UINavigationBar *)getTitleBar; - (void)backButtonHandler; @end2 工具类.m
// // TitleBarHelper.m #import "TitleBarHelper.h" #import "Public.h" @implementation TitleBarHelper { } // 初始化 -(id)initWithTitle:(NSString *)title ViewController:(UIViewController *)controller needBack:(BOOL) needBack{ self = [super init]; if (self) { self.viewController = controller; self.titleStr = title; self.needBack = needBack; } return self; } // 获取titleBar -(UINavigationBar *) getTitleBar{ UINavigationBar *titleBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screen_width, Title_Height)]; [titleBar setBarTintColor:Main_Color]; [titleBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil]]; UINavigationItem *titleItem = [[UINavigationItem alloc] initWithTitle:self.titleStr]; if (self.needBack) { UIBarButtonItem *leftButton = [UIBarButtonItem new]; UIButton *btnView = [UIButton buttonWithType:UIButtonTypeCustom]; [btnView setFrame:CGRectMake(0, 0, 40, 40)]; [btnView setBackgroundImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal]; [btnView addTarget:self.viewController action:@selector(backButtonHandler) forControlEvents:UIControlEventTouchUpInside]; [leftButton setCustomView:btnView]; [titleItem setLeftBarButtonItem:leftButton]; } [titleBar pushNavigationItem:titleItem animated:NO]; return titleBar; } // UIBarButtonItem点击事件 - (void)backButtonHandler { [self.viewController dismissViewControllerAnimated:YES completion:^{}]; } @end3. 使用该工具类的ViewController.m
// // OfflineHistoryViewController.m #import "OfflineHistoryViewController.h" #import "TitleBarHelper.h" @interface OfflineHistoryViewController (){ UINavigationBar *titleBar; } @end @implementation OfflineHistoryViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor grayColor]; [self initView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)initView{ [self initTitleBar]; } -(void)initTitleBar{ TitleBarHelper * titleBarHelper = [[TitleBarHelper alloc]initWithTitle:@"Title" ViewController:self needBack:YES]; titleBar = [titleBarHelper getTitleBar]; [self.view addSubview:titleBar]; } /* @end
ios – UINavigationBar -pushNavigationItem在将新控制器推送到UINavigationController堆栈时从不调用
- (void)pushController { PHViewController *ctrl2 = [[[PHViewController alloc] initWithNibName:@"PHViewController" bundle:nil] autorelease]; ctrl2.shouldShowPrompt = YES; [self.viewController pushViewController:ctrl2 animated:YES]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. PHViewController *ctrl = [[[PHViewController alloc] initWithNibName:@"PHViewController" bundle:nil] autorelease]; ctrl.shouldShowPrompt = YES; ctrl.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Push" style:UIBarButtonItemStyleDone target:self action:@selector(pushController)] autorelease]; self.viewController = [[[PHNavigationController alloc] initWithRootViewController:ctrl] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; }
现在我已经将UINavigationController的UINavigationBar子类化了(我知道这是非法的,这是一个教育问题)我已经覆盖了以下方法:
- (void)setItems:(NSArray *)items animated:(BOOL)animated { NSLog(@"Setting Navigation Item"); [super setItems:items animated:animated]; } - (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated { NSLog(@"Pushing Navigation Item"); [super pushNavigationItem:item animated:animated]; } - (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated { NSLog(@"Poping Navigation Item"); return [super popNavigationItemAnimated:animated]; } - (void)setValue:(id)value forKeyPath:(Nsstring *)keyPath { NSLog(@"Setting Value: %@ for keyPath:%@",value,keyPath); [super setValue:value forKeyPath:keyPath]; }
这是我的问题:为什么控制台中存在“弹出导航项”(因此被调用的方法)和“推送导航项”不是?
解决方法
还是非常感谢!
我们今天的关于为 iOS 7 半透明 UINavigationBar 实现明亮、生动的色彩和iphone半透明图标的分享就到这里,谢谢您的阅读,如果想了解更多关于IOS navigationbar 透明问题 -求解决方法、iOS UINavigationBar vs UIToolbar vs UITabBar、iOS UINavigationBar的工具类问题、ios – UINavigationBar -pushNavigationItem在将新控制器推送到UINavigationController堆栈时从不调用的相关信息,可以在本站进行搜索。
本文标签: