Coder Social home page Coder Social logo

ltnavigationbar's Introduction

LTNavigationbar

Deprecated

This lib uses a hacky way to achieve the result, in the new iOS version, the structure of UINavigation is changed and this lib no longer works anymore, so please check these alternatives:

swift version

https://github.com/ltebean/LTNavigationBar/tree/swift3.0

Purpose

It is hard to change the appearance of UINavigationBar dynamically, so I made this lib to make the job easy.

Demo

1. Changing the background color:

LTNavigationbar

2. Making navigation bar scroll along with a scroll view:

LTNavigationbar

Usage

First, import this lib:

#import "UINavigationBar+Awesome.h"

The category includes lots of method that helps to change UINavigationBar's appearance dynamically:

@interface UINavigationBar (Awesome)
- (void)lt_setBackgroundColor:(UIColor *)backgroundColor;
- (void)lt_setElementsAlpha:(CGFloat)alpha;
- (void)lt_setTranslationY:(CGFloat)translationY;
- (void)lt_reset;
@end

You can call the various setter wherever you want, like:

[self.navigationController.navigationBar lt_setBackgroundColor:[UIColor blueColor]];

And usually in viewWillDisappear, you should call this method to avoid any side effects:

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar lt_reset];
}

See the example for details~

ltnavigationbar's People

Contributors

ltebean avatar michal-czw avatar vianpan avatar wanghengheng avatar xzenon avatar zhwayne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ltnavigationbar's Issues

CAGradient Background Layer

I would like the NavigationBar to use a gradient background layer when it is in the transparent state. Some images have very light colors which makes the navigation bar content elements nearly invisible.

What is the best way to do that?

Crashed on iOS11

I used a single UINavigationBar(NOT UINavigationController), App crashed on lt_setBackgroundColor method. It seems that UINavigationBar subviews structure has changed.

有个问题

当我在 AppDelegate.m 中调用了如下代码:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navBg"]
                                  forBarPosition:UIBarPositionTopAttached
                                      barMetrics:UIBarMetricsDefault];

LCNavigationBar 就会失效,如下图:
simulator

不知道原来作者去什么地方了,现在显示不出来的可以这样解决的

把这个文件UINavigationBar+Awesome.h 里面的方法lt_setBackgroundColor 改成这样就解决了

- (void)lt_setBackgroundColor:(UIColor *)backgroundColor
{
    if (!self.overlay) {
        [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds) + 20)];
        self.overlay.userInteractionEnabled = NO;
        self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    }
    [self insertSubview:self.overlay atIndex:0];
    self.overlay.backgroundColor = backgroundColor;
}

因为返回回来之后self.overlay就跑最上面一层去了,并没有在最后面,所以就挡到了,显示不出来了
每次这样手动处理一下就好了

不能实现渐变色啊。

我有一个方法会频繁调用

- (void)handlePopGesture:(UIPanGestureRecognizer *)popGesture
{
    // 计算用户手指划了多远
    CGFloat progress = [popGesture translationInView:self.view].x / (self.view.bounds.size.width * 1.0);
    progress = MIN(1.0, MAX(0.0, progress));
    YPLog(@"%f",progress);

    CGFloat r = _endR - _startR;
    CGFloat g = _endG - _startG;
    CGFloat b = _endB - _startB;

    UIColor *endColor = [UIColor colorWithRed:_startR + r * progress green:_startG + g * progress blue:_startB + b * progress alpha:1.0f];

    [self.navigationController.navigationBar lt_setBackgroundColor:endColor];
}

随着进度改变Bar的背景颜色。。 发现不好用 颜色不会变

Device iOS10 , the navigationbar is heighter.

  1. I use the code that it judge the version.
    But the new code does not judge the version.
    Now if the new code and the device version is ios10, the navigationbar is hegihter.
  2. I set the backgroundcolor in the "ViewDidAppear"
    If the controller is the navigationController's rootViewController , the navigationBar will move up 20.
    But I set the backgroundColor in "viewDidLoad" , the navigationBar is normal.

I donot know why...

When the device version is less than 10.0, the navigationBar display heighter.

I saw the code , when the version is less than 10.0, the overlay 's height is heighter 20 than before.
if (SYSTEM_VERSION_LESS_THAN(@"10.0")) { self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + 20)]; } else { self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + 20)]; }

Problem with back button not working

Awesome code for a nice effect, thank you. I have one problem where the back button does not work any longer when I navigate down a few layers. Any idea what that could be? It might be my code.

iOS 11 崩溃

LTNavigationBar[11369:4642197] [Accessibility] ****************** Loading GAX Client Bundle ****************
2017-06-28 14:30:40.795882+0800 LTNavigationBar[11369:4642197] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UINavigationBar 0x1039250a0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key _leftViews.'
*** First throw call stack:
(0x186ed9858 0x1856b0528 0x186ed9520 0x187a26e88 0x18796ceac 0x10367efc0 0x10367e05c 0x10367de80 0x18d9e000c 0x19d4e7f00 0x18d705b5c 0x18d7ab6c0 0x18d871a0c 0x18dd49978 0x18dd4df1c 0x18d862b9c 0x18d7181f4 0x18dd38364 0x18dd37f24 0x18dd37080 0x18d7164f4 0x18d6e7b38 0x19d4af210 0x18dfe9514 0x18dfeb984 0x18dfe4af0 0x186e80528 0x186e7fe0c 0x186e7d904 0x186d9c280 0x1888adf94 0x18d74b0f0 0x10367ea80 0x185b8de40)
libc++abi.dylib: terminating with uncaught exception of type NSException

NavigationBar loaded from Xcode8 xib issue

In Xcode8, size of any UIView loaded from xib has changed to be (1000, 1000). So if I load a single UINavigationBar(not from UINavigationController) from xib, its height will be 1020, the view of UIViewController will be covered by the overlay, which is added by LTNavigationBar.

Solution: Auto layout should be used, don't use "self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth;" Just like the following:

// self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth; // Comment out this line
self.overlay.translatesAutoresizingMaskIntoConstraints = NO;
[[self.subviews firstObject] insertSubview:self.overlay atIndex:0];
NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(0)-[overlay]-(0)-|" options:0 metrics:nil views:@{@"overlay":self.overlay}];
NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(-20)-[overlay]-(0)-|" options:0 metrics:nil views:@{@"overlay":self.overlay}];
[self.overlay.superview addConstraints:hConstraints];
[self.overlay.superview addConstraints:vConstraints];

Navigation bar disappears when going back

Steps to reproduce:

  • start demo project in iPhone 5 Simulator with iOS 8.2
  • make sure screen is scrolled to the very top
  • tap + button on navigation bar
  • tap Back button on navigation bar

Expected results:

  • navigation bar should be visible during view controllers transitions

Results:

  • navigation bar disappears during view controllers transitions

Animated screenshot:

LTNavigationBar-issue

ios10适配

如果导航栏设置了透明的话,iOS10上面导航栏完全是是白色的标题也看不清。

TopView is to small

I tried to create your example in code instead of in the storyboard.

In AppDelegate I created:

let vc = Page1ViewController()
window?.rootViewController = UINavigationController(rootViewController: vc)

Page1ViewController is:

@objc(Page1ViewController)
class Page1ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

  let cellIndentifier = "cell"
  let NAVBAR_CHANGE_POINT:CGFloat = 50

  @IBOutlet weak var tableView: UITableView!
  var topView:UIView!
  var topImageView: UIImageView?


  override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "someAction"), animated: true)

    self.tableView.delegate = self
    self.tableView.dataSource = self
    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIndentifier)
    self.navigationController?.navigationBar.lt_setBackgroundColor(UIColor.clearColor())


    topView = UIView(frame: CGRectMake(0, 0, 320, 212))
    topView.backgroundColor = UIColor.yellowColor()
    tableView.addSubview(topView)


    let img = UIImage(named: "bg2")
    topImageView = UIImageView(image: img)
    topImageView?.frame = CGRectMake(0, -89, 320, 307)
    topImageView?.contentMode = UIViewContentMode.ScaleToFill
    topView.addSubview(topImageView!)

    topView.superview?.sendSubviewToBack(topView)

  }
  ...
}

In the nib of Page1ViewController I just inserted a UITableView and linked the outlet to tableView.

Here is the result when I run the app:

ios_simulator_-iphone_5-iphone_5___ios_7_1__11d167

It works like your demo app with the exception that the header does not have the correct height. How can I change that?

Thanks for help!

iOS 10 Navigation bar is not set to transparent

I am writing code for app with future support so basically i'm looking at all side previous versions, current version, as well as future version which will be iOS 10.

This category works perfect until iOS 9.3.3 but in iOS 10 its not working, i've tested on both iDevice and Simulator

I'm setting clear colour for navigation bar at viewDidLoad as below

[self.navigationController.navigationBar setShadowImage:[UIImage new]]; [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];

Please someone help me out with this.

I'm sorry for my english, i don't know what language you're using 😜

Thanks.

reset 无效

  • (void)viewWillDisappear:(BOOL)animated
    {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar lt_reset];
    }

push to other Controller navigationBar color can not set to default

滑动返回,导航栏空白

最新的demo中,从第一个标签页导航栏透明的情况下跳转到一共空白页面,滑动返回,空白页面的导航栏也是白的。

iOS 10 Issue

I have an issue since iOS 10, the fade animation I used for my scroll view also hide the menu icon and the navigation bar title.
When I navigate threw my App, the color that I used with lt_setBackgroundColor on my HomeViewController override all my navigation bar titles / menu icons, so they appear hidden.

If I call [self.navigationController.navigationBar lt_reset], I can clearly see them all but the color background is back to white.

The behaviour was working perfectly since xCode 8 / iOS 10, and is still working when I launch my App with an iPhone < iOS 10.

I would like to know what changed and how can I fix it?

not work for the navigationbar contained in ABPeoplePickerNavigationController

'''
UINavigationBar *navigationBar = [UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil];
[navigationBar lt_setBackgroundColor:[UIColor colorWithHexString:@"#0065A1"]];

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
'''

the background color has no effect

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.