Skip to content

Commit

Permalink
修复由后台返回前台,导航栏分割线会闪烁的问题 #163
Browse files Browse the repository at this point in the history
  • Loading branch information
listenzz committed Aug 2, 2022
1 parent 3f2811a commit 49f68d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions HBDNavigationBar/Classes/HBDNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import "HBDNavigationBar.h"
#import <objc/runtime.h>

#define hairlineWidth (1.f/[UIScreen mainScreen].scale)

static void hbd_exchangeImplementations(Class class, SEL originalSelector, SEL swizzledSelector) {
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
Expand Down Expand Up @@ -97,7 +99,7 @@ - (void)layoutSubviews {
[super layoutSubviews];
self.fakeView.frame = self.fakeView.superview.bounds;
self.backgroundImageView.frame = self.backgroundImageView.superview.bounds;
self.shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.shadowImageView.superview.bounds) - 0.5, CGRectGetWidth(self.shadowImageView.superview.bounds), 0.5);
self.shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.shadowImageView.superview.bounds) - hairlineWidth, CGRectGetWidth(self.shadowImageView.superview.bounds), hairlineWidth);
}

- (void)setBarTintColor:(UIColor *)barTintColor {
Expand Down Expand Up @@ -171,6 +173,7 @@ - (UIImageView *)shadowImageView {
_shadowImageView = [[UIImageView alloc] init];
_shadowImageView.userInteractionEnabled = NO;
_shadowImageView.contentScaleFactor = 1;
_shadowImageView.layer.allowsEdgeAntialiasing = YES;
[[self.subviews firstObject] insertSubview:_shadowImageView aboveSubview:self.backgroundImageView];
}
return _shadowImageView;
Expand All @@ -186,7 +189,7 @@ - (void)makeSureFakeView {

if (!self.shadowImageView.superview) {
[[self.subviews firstObject] insertSubview:_shadowImageView aboveSubview:self.backgroundImageView];
self.shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.shadowImageView.superview.bounds) - 0.5, CGRectGetWidth(self.shadowImageView.superview.bounds), 0.5);
self.shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.shadowImageView.superview.bounds) - hairlineWidth, CGRectGetWidth(self.shadowImageView.superview.bounds), hairlineWidth);
}

if (!self.backgroundImageView.superview) {
Expand Down

0 comments on commit 49f68d9

Please sign in to comment.