cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/UIKitExtensions/QMUIBarProtocol/UINavigationBar+QMUIBarProtocol.m

120 lines
5.6 KiB
Mathematica
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// UINavigationBar+QMUIBarProtocol.m
// QMUIKit
//
// Created by molice on 2022/5/18.
//
#import "UINavigationBar+QMUIBarProtocol.h"
#import "QMUIBarProtocolPrivate.h"
#import "QMUICore.h"
#import "UIVisualEffectView+QMUI.h"
#import "NSArray+QMUI.h"
@interface UINavigationBar ()<QMUIBarProtocolPrivate>
@end
@implementation UINavigationBar (QMUIBarProtocol)
QMUISynthesizeBOOLProperty(qmuibar_hasSetEffect, setQmuibar_hasSetEffect)
QMUISynthesizeBOOLProperty(qmuibar_hasSetEffectForegroundColor, setQmuibar_hasSetEffectForegroundColor)
BeginIgnoreClangWarning(-Wobjc-protocol-method-implementation)
- (void)qmuibar_updateEffect {
[self.qmui_effectViews enumerateObjectsUsingBlock:^(UIVisualEffectView * _Nonnull effectView, NSUInteger idx, BOOL * _Nonnull stop) {
if (self.qmuibar_hasSetEffect) {
// iOS 13 使 UITabBarAppearance.backgroundEffect iOS 10 13 setBackgroundEffects: UITabBarAppearance UIAppearance
NSArray<UIVisualEffect *> *effects = self.qmuibar_backgroundEffects;
[effectView qmui_performSelector:NSSelectorFromString(@"setBackgroundEffects:") withArguments:&effects, nil];
}
if (self.qmuibar_hasSetEffectForegroundColor) {
effectView.qmui_foregroundColor = self.qmui_effectForegroundColor;
}
}];
}
EndIgnoreClangWarning
// UITabBarUIVisualEffectView backgroundEffects UIVisualEffectView UITabBar backgroundEffects effect 便 UITabBar (QMUI).effect backgroundEffects
- (NSArray<UIVisualEffect *> *)qmuibar_backgroundEffects {
if (self.qmuibar_hasSetEffect) {
return self.qmui_effect ? @[self.qmui_effect] : nil;
}
return nil;
}
#pragma mark - <QMUIBarProtocol>
- (UIView *)qmui_backgroundView {
return [self qmui_valueForKey:@"_backgroundView"];
}
- (UIImageView *)qmui_shadowImageView {
// bar init backgroundView shadowView
return [self.qmui_backgroundView qmui_valueForKey:@"_shadowView1"];
}
- (UIVisualEffectView *)qmui_effectView {
NSArray<UIVisualEffectView *> *visibleEffectViews = [self.qmui_effectViews qmui_filterWithBlock:^BOOL(UIVisualEffectView * _Nonnull item) {
return !item.hidden && item.alpha > 0.01 && item.superview;
}];
return visibleEffectViews.lastObject;
}
- (NSArray<UIVisualEffectView *> *)qmui_effectViews {
UIView *backgroundView = self.qmui_backgroundView;
NSMutableArray<UIVisualEffectView *> *result = NSMutableArray.new;
UIVisualEffectView *backgroundEffectView1 = [backgroundView valueForKey:@"_effectView1"];
UIVisualEffectView *backgroundEffectView2 = [backgroundView valueForKey:@"_effectView2"];
if (backgroundEffectView1) {
[result addObject:backgroundEffectView1];
}
if (backgroundEffectView2) {
[result addObject:backgroundEffectView2];
}
return result.count > 0 ? result : nil;
}
static char kAssociatedObjectKey_effect;
- (void)setQmui_effect:(UIBlurEffect *)qmui_effect {
if (qmui_effect) {
[QMUIBarProtocolPrivate swizzleBarBackgroundViewIfNeeded];
}
BOOL valueChanged = self.qmui_effect != qmui_effect;
objc_setAssociatedObject(self, &kAssociatedObjectKey_effect, qmui_effect, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if (valueChanged) {
self.qmuibar_hasSetEffect = YES;// QMUITheme nil nil hasSet if (valueChanged)
[self qmuibar_updateEffect];
}
}
- (UIBlurEffect *)qmui_effect {
return (UIBlurEffect *)objc_getAssociatedObject(self, &kAssociatedObjectKey_effect);
}
static char kAssociatedObjectKey_effectForegroundColor;
- (void)setQmui_effectForegroundColor:(UIColor *)qmui_effectForegroundColor {
if (qmui_effectForegroundColor) {
[QMUIBarProtocolPrivate swizzleBarBackgroundViewIfNeeded];
}
BOOL valueChanged = ![self.qmui_effectForegroundColor isEqual:qmui_effectForegroundColor];
objc_setAssociatedObject(self, &kAssociatedObjectKey_effectForegroundColor, qmui_effectForegroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if (valueChanged) {
self.qmuibar_hasSetEffectForegroundColor = YES;// QMUITheme nil nil hasSet if (valueChanged)
[self qmuibar_updateEffect];
}
}
- (UIColor *)qmui_effectForegroundColor {
return (UIColor *)objc_getAssociatedObject(self, &kAssociatedObjectKey_effectForegroundColor);
}
@end