Skip to content

Commit 18521d2

Browse files
authored
Merge pull request #1 from CloudlessMoon/master
适配iOS 26, 修复崩溃bug
2 parents 6bd3079 + a977cbb commit 18521d2

46 files changed

Lines changed: 658 additions & 235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

QMUIKit/QMUIComponents/NavigationBarTransition/UINavigationBar+Transition.m

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#import "UINavigationBar+QMUI.h"
1919
#import "UINavigationBar+QMUIBarProtocol.h"
2020
#import "QMUIWeakObjectContainer.h"
21+
#import "QMUIBarProtocolPrivate.h"
2122
#import "UIImage+QMUI.h"
23+
#import "CALayer+QMUI.h"
2224

2325
@implementation UINavigationBar (Transition)
2426

@@ -51,7 +53,7 @@ + (void)load {
5153
originSelectorIMP(selfObject, originCMD, appearance);
5254

5355
if (selfObject.qmuinb_copyStylesToBar) {
54-
selfObject.qmuinb_copyStylesToBar.standardAppearance = appearance;
56+
selfObject.qmuinb_copyStylesToBar.scrollEdgeAppearance = appearance;
5557
}
5658
};
5759
});
@@ -222,6 +224,21 @@ + (void)load {
222224
});
223225
}
224226

227+
OverrideImplementation(NSClassFromString(@"_UIBarBackground"), @selector(didMoveToWindow), ^id(__unsafe_unretained Class originClass, SEL originCMD, IMP (^originalIMPProvider)(void)) {
228+
return ^(UIView *selfObject) {
229+
230+
// call super
231+
void (*originSelectorIMP)(id, SEL);
232+
originSelectorIMP = (void (*)(id, SEL))originalIMPProvider();
233+
originSelectorIMP(selfObject, originCMD);
234+
235+
_QMUITransitionNavigationBar *navigationBar = (_QMUITransitionNavigationBar *)selfObject.superview;
236+
if (selfObject.window != nil && [navigationBar isKindOfClass:_QMUITransitionNavigationBar.class]) {
237+
[navigationBar updateLayout];
238+
}
239+
};
240+
});
241+
225242
#ifdef IOS15_SDK_ALLOWED
226243
if (@available(iOS 15.0, *)) {
227244
// - [UINavigationBar _didMoveFromWindow:toWindow:]
@@ -255,9 +272,12 @@ - (void)setOriginalNavigationBar:(UINavigationBar *)originBar {
255272
}
256273

257274
- (void)layoutSubviews {
258-
[super layoutSubviews];
259-
// 实测 iOS 11 Beta 1-5 里,自己 init 的 navigationBar.backgroundView.height 默认一直是 44,所以才加上这个兼容
260-
self.qmui_backgroundView.frame = self.bounds;
275+
[CALayer qmui_performWithoutAnimation:^{
276+
[super layoutSubviews];
277+
// 实测 iOS 11 Beta 1-5 里,自己 init 的 navigationBar.backgroundView.height 默认一直是 44,所以才加上这个兼容
278+
self.qmui_backgroundView.frame = self.bounds;
279+
[self.qmui_backgroundView layoutIfNeeded];
280+
}];
261281
}
262282

263283
// NavBarRemoveBackgroundEffectAutomatically 在开启了 AutomaticCustomNavigationBarTransitionStyle 时可能对假 bar 无效
@@ -274,7 +294,12 @@ - (void)updateLayout {
274294
[self.parentViewController.view bringSubviewToFront:self];
275295
UIView *backgroundView = self.originalNavigationBar.qmui_backgroundView;
276296
CGRect rect = [backgroundView.superview convertRect:backgroundView.frame toView:self.parentViewController.view];
277-
self.frame = CGRectSetX(rect, 0);// push/pop 过程中系统的导航栏转换过来的 x 可能是 112、-112
297+
[CALayer qmui_performWithoutAnimation:^{
298+
// push/pop 过程中系统的导航栏转换过来的 x 可能是 112、-112
299+
// iOS 26上,y 可能是 -113
300+
self.frame = CGRectSetXY(rect, 0, 0);
301+
[self layoutIfNeeded];
302+
}];
278303
}
279304
}
280305

QMUIKit/QMUIComponents/NavigationBarTransition/UINavigationController+NavigationBarTransition.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ - (void)addTransitionNavigationBarAndBindNavigationBar:(BOOL)shouldBind {
231231
}
232232

233233
_QMUITransitionNavigationBar *customBar = [[_QMUITransitionNavigationBar alloc] init];
234+
/// iOS 26不设置items时子视图不会添加
235+
customBar.items = @[[[UINavigationItem alloc] initWithTitle:@""]];
234236
customBar.parentViewController = self;
235237
self.transitionNavigationBar = customBar;
236238

QMUIKit/QMUIComponents/QMUIAlertController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ typedef NS_ENUM(NSInteger, QMUIAlertControllerStyle) {
241241
/// 显示`QMUIAlertController`
242242
- (void)showWithAnimated:(BOOL)animated;
243243

244+
/// 显示`QMUIAlertController`
245+
- (void)showInWindow:(nullable UIWindow *)window animated:(BOOL)animated;
246+
244247
/// 隐藏`QMUIAlertController`
245248
- (void)hideWithAnimated:(BOOL)animated;
246249

QMUIKit/QMUIComponents/QMUIAlertController.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,10 @@ - (void)customModalPresentationControllerAnimation {
891891
}
892892

893893
- (void)showWithAnimated:(BOOL)animated {
894+
[self showInWindow:nil animated:animated];
895+
}
896+
897+
- (void)showInWindow:(nullable UIWindow *)window animated:(BOOL)animated {
894898
if (self.willShow || self.showing) {
895899
return;
896900
}
@@ -918,7 +922,7 @@ - (void)showWithAnimated:(BOOL)animated {
918922

919923
__weak __typeof(self)weakSelf = self;
920924

921-
[self.modalPresentationViewController showWithAnimated:animated completion:^(BOOL finished) {
925+
[self.modalPresentationViewController showInWindow:window animated:animated completion:^(BOOL finished) {
922926
weakSelf.dimmingView.alpha = 1;
923927
weakSelf.willShow = NO;
924928
weakSelf.showing = YES;

QMUIKit/QMUIComponents/QMUIBadge/UIBarItem+QMUIBadge.m

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ - (void)setQmui_badgeString:(NSString *)qmui_badgeString {
8787
[self updateViewDidSetBlockIfNeeded];
8888
}
8989
self.qmui_view.qmui_badgeString = qmui_badgeString;
90+
self.qmui_selectedView.qmui_badgeString = qmui_badgeString;
9091
}
9192

9293
- (NSString *)qmui_badgeString {
@@ -97,6 +98,7 @@ - (NSString *)qmui_badgeString {
9798
- (void)setQmui_badgeBackgroundColor:(UIColor *)qmui_badgeBackgroundColor {
9899
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeBackgroundColor, qmui_badgeBackgroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
99100
self.qmui_view.qmui_badgeBackgroundColor = qmui_badgeBackgroundColor;
101+
self.qmui_selectedView.qmui_badgeBackgroundColor = qmui_badgeBackgroundColor;
100102
}
101103

102104
- (UIColor *)qmui_badgeBackgroundColor {
@@ -107,6 +109,7 @@ - (UIColor *)qmui_badgeBackgroundColor {
107109
- (void)setQmui_badgeTextColor:(UIColor *)qmui_badgeTextColor {
108110
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeTextColor, qmui_badgeTextColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
109111
self.qmui_view.qmui_badgeTextColor = qmui_badgeTextColor;
112+
self.qmui_selectedView.qmui_badgeTextColor = qmui_badgeTextColor;
110113
}
111114

112115
- (UIColor *)qmui_badgeTextColor {
@@ -117,6 +120,7 @@ - (UIColor *)qmui_badgeTextColor {
117120
- (void)setQmui_badgeFont:(UIFont *)qmui_badgeFont {
118121
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeFont, qmui_badgeFont, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
119122
self.qmui_view.qmui_badgeFont = qmui_badgeFont;
123+
self.qmui_selectedView.qmui_badgeFont = qmui_badgeFont;
120124
}
121125

122126
- (UIFont *)qmui_badgeFont {
@@ -127,6 +131,7 @@ - (UIFont *)qmui_badgeFont {
127131
- (void)setQmui_badgeContentEdgeInsets:(UIEdgeInsets)qmui_badgeContentEdgeInsets {
128132
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeContentEdgeInsets, [NSValue valueWithUIEdgeInsets:qmui_badgeContentEdgeInsets], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
129133
self.qmui_view.qmui_badgeContentEdgeInsets = qmui_badgeContentEdgeInsets;
134+
self.qmui_selectedView.qmui_badgeContentEdgeInsets = qmui_badgeContentEdgeInsets;
130135
}
131136

132137
- (UIEdgeInsets)qmui_badgeContentEdgeInsets {
@@ -137,6 +142,7 @@ - (UIEdgeInsets)qmui_badgeContentEdgeInsets {
137142
- (void)setQmui_badgeOffset:(CGPoint)qmui_badgeOffset {
138143
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeOffset, @(qmui_badgeOffset), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
139144
self.qmui_view.qmui_badgeOffset = qmui_badgeOffset;
145+
self.qmui_selectedView.qmui_badgeOffset = qmui_badgeOffset;
140146
}
141147

142148
- (CGPoint)qmui_badgeOffset {
@@ -147,6 +153,7 @@ - (CGPoint)qmui_badgeOffset {
147153
- (void)setQmui_badgeOffsetLandscape:(CGPoint)qmui_badgeOffsetLandscape {
148154
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeOffsetLandscape, @(qmui_badgeOffsetLandscape), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
149155
self.qmui_view.qmui_badgeOffsetLandscape = qmui_badgeOffsetLandscape;
156+
self.qmui_selectedView.qmui_badgeOffsetLandscape = qmui_badgeOffsetLandscape;
150157
}
151158

152159
- (CGPoint)qmui_badgeOffsetLandscape {
@@ -155,6 +162,8 @@ - (CGPoint)qmui_badgeOffsetLandscape {
155162

156163
- (void)setQmui_badgeView:(__kindof UIView *)qmui_badgeView {
157164
self.qmui_view.qmui_badgeView = qmui_badgeView;
165+
/// iOS 26,需要改成block?
166+
// self.qmui_selectedView.qmui_badgeView = qmui_badgeView;
158167
}
159168

160169
- (__kindof UIView *)qmui_badgeView {
@@ -163,6 +172,7 @@ - (__kindof UIView *)qmui_badgeView {
163172

164173
- (void)setQmui_badgeViewDidLayoutBlock:(void (^)(__kindof UIView * _Nonnull, __kindof UIView * _Nonnull))qmui_badgeViewDidLayoutBlock {
165174
self.qmui_view.qmui_badgeViewDidLayoutBlock = qmui_badgeViewDidLayoutBlock;
175+
self.qmui_selectedView.qmui_badgeViewDidLayoutBlock = qmui_badgeViewDidLayoutBlock;
166176
}
167177

168178
- (void (^)(__kindof UIView * _Nonnull, __kindof UIView * _Nonnull))qmui_badgeViewDidLayoutBlock {
@@ -178,6 +188,7 @@ - (void)setQmui_shouldShowUpdatesIndicator:(BOOL)qmui_shouldShowUpdatesIndicator
178188
[self updateViewDidSetBlockIfNeeded];
179189
}
180190
self.qmui_view.qmui_shouldShowUpdatesIndicator = qmui_shouldShowUpdatesIndicator;
191+
self.qmui_selectedView.qmui_shouldShowUpdatesIndicator = qmui_shouldShowUpdatesIndicator;
181192
}
182193

183194
- (BOOL)qmui_shouldShowUpdatesIndicator {
@@ -188,6 +199,7 @@ - (BOOL)qmui_shouldShowUpdatesIndicator {
188199
- (void)setQmui_updatesIndicatorColor:(UIColor *)qmui_updatesIndicatorColor {
189200
objc_setAssociatedObject(self, &kAssociatedObjectKey_updatesIndicatorColor, qmui_updatesIndicatorColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
190201
self.qmui_view.qmui_updatesIndicatorColor = qmui_updatesIndicatorColor;
202+
self.qmui_selectedView.qmui_updatesIndicatorColor = qmui_updatesIndicatorColor;
191203
}
192204

193205
- (UIColor *)qmui_updatesIndicatorColor {
@@ -198,6 +210,7 @@ - (UIColor *)qmui_updatesIndicatorColor {
198210
- (void)setQmui_updatesIndicatorSize:(CGSize)qmui_updatesIndicatorSize {
199211
objc_setAssociatedObject(self, &kAssociatedObjectKey_updatesIndicatorSize, [NSValue valueWithCGSize:qmui_updatesIndicatorSize], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
200212
self.qmui_view.qmui_updatesIndicatorSize = qmui_updatesIndicatorSize;
213+
self.qmui_selectedView.qmui_updatesIndicatorSize = qmui_updatesIndicatorSize;
201214
}
202215

203216
- (CGSize)qmui_updatesIndicatorSize {
@@ -208,6 +221,7 @@ - (CGSize)qmui_updatesIndicatorSize {
208221
- (void)setQmui_updatesIndicatorOffset:(CGPoint)qmui_updatesIndicatorOffset {
209222
objc_setAssociatedObject(self, &kAssociatedObjectKey_updatesIndicatorOffset, @(qmui_updatesIndicatorOffset), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
210223
self.qmui_view.qmui_updatesIndicatorOffset = qmui_updatesIndicatorOffset;
224+
self.qmui_selectedView.qmui_updatesIndicatorOffset = qmui_updatesIndicatorOffset;
211225
}
212226

213227
- (CGPoint)qmui_updatesIndicatorOffset {
@@ -218,6 +232,7 @@ - (CGPoint)qmui_updatesIndicatorOffset {
218232
- (void)setQmui_updatesIndicatorOffsetLandscape:(CGPoint)qmui_updatesIndicatorOffsetLandscape {
219233
objc_setAssociatedObject(self, &kAssociatedObjectKey_updatesIndicatorOffsetLandscape, @(qmui_updatesIndicatorOffsetLandscape), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
220234
self.qmui_view.qmui_updatesIndicatorOffsetLandscape = qmui_updatesIndicatorOffsetLandscape;
235+
self.qmui_selectedView.qmui_updatesIndicatorOffsetLandscape = qmui_updatesIndicatorOffsetLandscape;
221236
}
222237

223238
- (CGPoint)qmui_updatesIndicatorOffsetLandscape {
@@ -226,6 +241,8 @@ - (CGPoint)qmui_updatesIndicatorOffsetLandscape {
226241

227242
- (void)setQmui_updatesIndicatorView:(__kindof UIView *)qmui_updatesIndicatorView {
228243
self.qmui_view.qmui_updatesIndicatorView = qmui_updatesIndicatorView;
244+
/// iOS 26,需要改成block?
245+
// self.qmui_selectedView.qmui_updatesIndicatorView = qmui_updatesIndicatorView;
229246
}
230247

231248
- (UIView *)qmui_updatesIndicatorView {
@@ -234,6 +251,7 @@ - (UIView *)qmui_updatesIndicatorView {
234251

235252
- (void)setQmui_updatesIndicatorViewDidLayoutBlock:(void (^)(__kindof UIView * _Nonnull, __kindof UIView * _Nonnull))qmui_updatesIndicatorViewDidLayoutBlock {
236253
self.qmui_view.qmui_updatesIndicatorViewDidLayoutBlock = qmui_updatesIndicatorViewDidLayoutBlock;
254+
self.qmui_selectedView.qmui_updatesIndicatorViewDidLayoutBlock = qmui_updatesIndicatorViewDidLayoutBlock;
237255
}
238256

239257
- (void (^)(__kindof UIView * _Nonnull, __kindof UIView * _Nonnull))qmui_updatesIndicatorViewDidLayoutBlock {
@@ -242,23 +260,75 @@ - (void)setQmui_updatesIndicatorViewDidLayoutBlock:(void (^)(__kindof UIView * _
242260

243261
#pragma mark - Common
244262

263+
- (nullable UIView *)qmui_selectedView {
264+
if (QMUIHelper.isUsedLiquidGlass) {
265+
if (![self isKindOfClass:UITabBarItem.class]) {
266+
return nil;
267+
}
268+
UIView *view = self.qmui_view;
269+
if (!view) {
270+
return nil;
271+
}
272+
NSInteger index = [view.superview.subviews indexOfObject:view];
273+
if (index == NSNotFound) {
274+
return nil;
275+
}
276+
UIView *platterView = view.superview.superview;
277+
if (![NSStringFromClass(platterView.class) hasSuffix:@"_UITabBarPlatterView"]) {
278+
return nil;
279+
}
280+
UIView *selectedContentView = platterView.subviews.firstObject;
281+
if (![NSStringFromClass(selectedContentView.class) hasSuffix:@"SelectedContentView"]) {
282+
return nil;
283+
}
284+
if (index < selectedContentView.subviews.count) {
285+
UIView *selectedView = [selectedContentView.subviews objectAtIndex:index];
286+
return selectedView;
287+
}
288+
}
289+
return nil;
290+
}
291+
245292
- (void)updateViewDidSetBlockIfNeeded {
246293
if (!self.qmui_viewDidSetBlock) {
247294
self.qmui_viewDidSetBlock = ^(__kindof UIBarItem * _Nonnull item, UIView * _Nullable view) {
295+
UIView *selectedView = item.qmui_selectedView;
296+
248297
view.qmui_badgeBackgroundColor = item.qmui_badgeBackgroundColor;
298+
selectedView.qmui_badgeBackgroundColor = item.qmui_badgeBackgroundColor;
299+
249300
view.qmui_badgeTextColor = item.qmui_badgeTextColor;
301+
selectedView.qmui_badgeTextColor = item.qmui_badgeTextColor;
302+
250303
view.qmui_badgeFont = item.qmui_badgeFont;
304+
selectedView.qmui_badgeFont = item.qmui_badgeFont;
305+
251306
view.qmui_badgeContentEdgeInsets = item.qmui_badgeContentEdgeInsets;
307+
selectedView.qmui_badgeContentEdgeInsets = item.qmui_badgeContentEdgeInsets;
308+
252309
view.qmui_badgeOffset = item.qmui_badgeOffset;
310+
selectedView.qmui_badgeOffset = item.qmui_badgeOffset;
311+
253312
view.qmui_badgeOffsetLandscape = item.qmui_badgeOffsetLandscape;
313+
selectedView.qmui_badgeOffsetLandscape = item.qmui_badgeOffsetLandscape;
254314

255315
view.qmui_updatesIndicatorColor = item.qmui_updatesIndicatorColor;
316+
selectedView.qmui_updatesIndicatorColor = item.qmui_updatesIndicatorColor;
317+
256318
view.qmui_updatesIndicatorSize = item.qmui_updatesIndicatorSize;
319+
selectedView.qmui_updatesIndicatorSize = item.qmui_updatesIndicatorSize;
320+
257321
view.qmui_updatesIndicatorOffset = item.qmui_updatesIndicatorOffset;
322+
selectedView.qmui_updatesIndicatorOffset = item.qmui_updatesIndicatorOffset;
323+
258324
view.qmui_updatesIndicatorOffsetLandscape = item.qmui_updatesIndicatorOffsetLandscape;
325+
selectedView.qmui_updatesIndicatorOffsetLandscape = item.qmui_updatesIndicatorOffsetLandscape;
259326

260327
view.qmui_badgeString = item.qmui_badgeString;
328+
selectedView.qmui_badgeString = item.qmui_badgeString;
329+
261330
view.qmui_shouldShowUpdatesIndicator = item.qmui_shouldShowUpdatesIndicator;
331+
selectedView.qmui_shouldShowUpdatesIndicator = item.qmui_shouldShowUpdatesIndicator;
262332
};
263333

264334
// 为 qmui_viewDidSetBlock 赋值前 item 已经 set 完 view,则手动触发一次

QMUIKit/QMUIComponents/QMUIBadge/UIView+QMUIBadge.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ - (void)updateLayoutSubviewsBlockIfNeeded {
322322
// 不管 image 还是 text 的 UIBarButtonItem 都获取内部的 _UIModernBarButton 即可
323323
- (UIView *)findBarButtonContentView {
324324
NSString *classString = NSStringFromClass(self.class);
325-
if ([classString isEqualToString:@"UITabBarButton"]) {
325+
if ([classString isEqualToString:@"UITabBarButton"] || [classString isEqualToString:@"_UITabButton"]) {
326326
// 特别的,对于 UITabBarItem,将 imageView 作为参考 view
327327
UIView *imageView = [UITabBarItem qmui_imageViewInTabBarButton:self];
328328
return imageView;

0 commit comments

Comments
 (0)