diff --git a/AwemeHeaders.h b/AwemeHeaders.h index c1f0e6b18..db94c2215 100644 --- a/AwemeHeaders.h +++ b/AwemeHeaders.h @@ -7,9 +7,20 @@ #define DYYYGetInteger(key) [[NSUserDefaults standardUserDefaults] integerForKey:key] #define DYYYGetString(key) [[NSUserDefaults standardUserDefaults] stringForKey:key] #define DYYY_IGNORE_GLOBAL_ALPHA_TAG 114514 + typedef NS_ENUM(NSInteger, MediaType) { MediaTypeVideo, MediaTypeImage, MediaTypeAudio, MediaTypeHeic }; -static __weak UICollectionView *gFeedCV = nil; +// 调节模式&全局状态 +typedef NS_ENUM(NSUInteger, DYEdgeMode) { + DYEdgeModeNone = 0, + DYEdgeModeBrightness = 1, + DYEdgeModeVolume = 2, +}; + +@interface UIView (DYYYGlobalAlpha) +- (void)dyyy_applyGlobalTransparency; +@end + // 音量控制 @interface AVSystemController : NSObject + (instancetype)sharedAVSystemController; @@ -21,15 +32,6 @@ static __weak UICollectionView *gFeedCV = nil; + (instancetype)sharedInstance; - (void)presentHUDWithIcon:(NSString *)name level:(float)level; @end -// 调节模式&全局状态 -typedef NS_ENUM(NSUInteger, DYEdgeMode) { - DYEdgeModeNone = 0, - DYEdgeModeBrightness = 1, - DYEdgeModeVolume = 2, -}; -static DYEdgeMode gMode = DYEdgeModeNone; -static CGFloat gStartY = 0.0; -static CGFloat gStartVal = 0.0; @interface URLModel : NSObject @property(nonatomic, strong) NSArray *originURLList; @@ -351,6 +353,9 @@ static CGFloat gStartVal = 0.0; @interface AWENormalModeTabBar : UIView @property(nonatomic, assign, readonly) UITabBarController *yy_viewController; @property(retain, nonatomic) AWETabBarSkinContainerView *skinContainerView; +- (void)initializeOriginalTabBarHeight; +- (void)calculateTabBarHeight; +- (BOOL)applyTabBarHeight; @end @interface AWEPlayInteractionListenFeedView : UIView diff --git a/DYYY.xm b/DYYY.xm index f3cabc87f..500190d49 100644 --- a/DYYY.xm +++ b/DYYY.xm @@ -23,7 +23,32 @@ #import "DYYYToast.h" #import "DYYYUtils.h" -static CGFloat DYYYCurrentTabHeight(void); +static CGFloat gStartY = 0.0; +static CGFloat gStartVal = 0.0; +static DYEdgeMode gMode = DYEdgeModeNone; +static __weak UICollectionView *gFeedCV = nil; + +static const CGFloat kInvalidAlpha = -1.0; +static const CGFloat kInvalidHeight = -1.0; +static CGFloat gGlobalTransparency = kInvalidAlpha; +static CGFloat gCurrentTabBarHeight = kInvalidHeight; +static CGFloat originalTabBarHeight = kInvalidHeight; +static NSString *const kDYYYGlobalTransparencyKey = @"DYYYGlobalTransparency"; +static NSString *const kDYYYGlobalTransparencyDidChangeNotification = @"DYYYGlobalTransparencyDidChangeNotification"; +static NSString *const kDYYYTabBarHeightKey = @"DYYYTabBarHeight"; + +static void updateGlobalTransparencyCache() { + NSString *transparentValue = DYYYGetString(kDYYYGlobalTransparencyKey); + if (transparentValue.length > 0) { + float alphaValue; + NSScanner *scanner = [NSScanner scannerWithString:transparentValue]; + if ([scanner scanFloat:&alphaValue] && scanner.isAtEnd) { + gGlobalTransparency = MIN(MAX(alphaValue, 0.0), 1.0); + return; + } + } + gGlobalTransparency = kInvalidAlpha; +} static NSDictionary *DYYYTopTabTitleMapping(void) { static NSString *cachedRawValue = nil; @@ -1010,6 +1035,7 @@ static CGFloat rightLabelRightMargin = -1; [parentView addSubview:leftLabel]; [DYYYUtils applyColorSettingsToLabel:leftLabel colorHexString:labelColorHex]; + [leftLabel dyyy_applyGlobalTransparency]; } if (!showLeftRemainingTime && !showLeftCompleteTime) { @@ -1034,6 +1060,7 @@ static CGFloat rightLabelRightMargin = -1; [parentView addSubview:rightLabel]; [DYYYUtils applyColorSettingsToLabel:rightLabel colorHexString:labelColorHex]; + [rightLabel dyyy_applyGlobalTransparency]; } [self setNeedsLayout]; @@ -1440,7 +1467,7 @@ static NSString *const kDYYYLongPressCopyEnabledKey = @"DYYYLongPressCopyTextEna - (void)didMoveToWindow { %orig; - if (DYYYGetBool(@"DYYYEnableNotificationTransparency")) { + if (self.window && DYYYGetBool(@"DYYYEnableNotificationTransparency")) { [self setupBlurEffectForNotificationView]; } } @@ -4295,11 +4322,10 @@ static CGFloat DYYYDesiredMTKViewShiftOffset(UIView *view) { if (viewWidth < screenWidth * 0.995f) { return 0.0f; } - CGFloat tabHeight = DYYYCurrentTabHeight(); - if (tabHeight <= 0.0f) { + if (gCurrentTabBarHeight <= 0.0f) { return 0.0f; } - return tabHeight * 0.5f; + return gCurrentTabBarHeight * 0.5f; } static void DYYYApplyMTKViewShiftIfNeeded(UIView *view) { @@ -4911,19 +4937,13 @@ static void DYYYApplyMTKViewShiftIfNeeded(UIView *view) { %end // 底栏高度 -static CGFloat tabHeight = 0; -static CGFloat originalTabHeight = 0; - -static CGFloat DYYYCurrentTabHeight(void) { return tabHeight; } - %hook AWENormalModeTabBar static Class barBackgroundClass = nil; static Class generalButtonClass = nil; static Class plusButtonClass = nil; static Class tabBarButtonClass = nil; -static NSString *const TabBarHeightKey = @"DYYYTabBarHeight"; -static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; +static void *DYYYTabBarHeightContext = &DYYYTabBarHeightContext; + (void)initialize { if (self == [%c(AWENormalModeTabBar) class]) { @@ -4934,70 +4954,139 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; } } +%new +- (void)initializeOriginalTabBarHeight { + if (originalTabBarHeight != kInvalidHeight) { + NSLog(@"[DYYY] initializeOriginalTabBarHeight: Skipped! originalTabBarHeight already initialized."); + return; + } + + UIWindow *targetWindow = self.window ?: [DYYYUtils getActiveWindow]; + if (self.frame.size.height >= 30) { + originalTabBarHeight = self.frame.size.height; + NSLog(@"[DYYY] initializeOriginalTabBarHeight: Success! originalTabBarHeight set to %.1f (from self.frame.size.height)", originalTabBarHeight); + } else if (targetWindow) { + CGFloat bottomInset = targetWindow.safeAreaInsets.bottom; + originalTabBarHeight = 49 + bottomInset; + NSLog(@"[DYYY] initializeOriginalTabBarHeight: Success! originalTabBarHeight set to %.1f (fallback calculation: 49.0 + %.1f)", originalTabBarHeight, bottomInset); + } else { + NSLog(@"[DYYY] initializeOriginalTabBarHeight: Failed! No window available."); + } +} + +%new +- (void)calculateTabBarHeight { + if (originalTabBarHeight == kInvalidHeight) { + NSLog(@"[DYYY] calculateTabBarHeight: Skipped! originalTabBarHeight not initialized yet."); + return; + } + + CGFloat newHeight = originalTabBarHeight; + NSString *tabBarHeightStr = [[NSUserDefaults standardUserDefaults] stringForKey:kDYYYTabBarHeightKey]; + + if (tabBarHeightStr.length > 0) { + float tabBarHeightValue; + NSScanner *scanner = [NSScanner scannerWithString:tabBarHeightStr]; + if ([scanner scanFloat:&tabBarHeightValue]) { + newHeight = MAX(tabBarHeightValue, 0.0); + } else { + NSLog(@"[DYYY] calculateTabBarHeight: Failed! Could not parse float value for key %@: '%@'", kDYYYTabBarHeightKey, tabBarHeightStr); + } + } + + if (fabs(gCurrentTabBarHeight - newHeight) > 0.1) { + NSLog(@"[DYYY] calculateTabBarHeight: Success! gCurrentTabBarHeight updated from %.1f to %.1f", gCurrentTabBarHeight, newHeight); + gCurrentTabBarHeight = newHeight; + } +} + +%new +- (BOOL)applyTabBarHeight { + if (gCurrentTabBarHeight == kInvalidHeight) { + NSLog(@"[DYYY] applyTabBarHeight: Skipped! gCurrentTabBarHeight not calculated yet."); + return NO; + } + + CGRect frame = self.frame; + if (fabs(frame.size.height - gCurrentTabBarHeight) < 0.1) { + NSLog(@"[DYYY] applyTabBarHeight: Skipped! Frame height already applied."); + return NO; + } + + if ([self respondsToSelector:@selector(setDesiredHeight:)]) { + ((void (*)(id, SEL, double))objc_msgSend)(self, @selector(setDesiredHeight:), gCurrentTabBarHeight); + } + + frame.size.height = gCurrentTabBarHeight; + if (self.superview) { + frame.origin.y = self.superview.bounds.size.height - gCurrentTabBarHeight; + } + self.frame = frame; + NSLog(@"[DYYY] applyTabBarHeight: Success! Frame height applied to %.1f", gCurrentTabBarHeight); + return YES; +} + - (instancetype)initWithFrame:(CGRect)frame { self = %orig; if (self) { - [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:TabBarHeightKey options:NSKeyValueObservingOptionNew context:TabBarHeightObservationContext]; + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:kDYYYTabBarHeightKey options:NSKeyValueObservingOptionNew context:DYYYTabBarHeightContext]; } return self; } - (void)dealloc { @try { - [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:TabBarHeightKey context:TabBarHeightObservationContext]; + [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:kDYYYTabBarHeightKey context:DYYYTabBarHeightContext]; } @catch (NSException *exception) { NSLog(@"[DYYY] KVO removeObserver failed: %@", exception); } %orig; } -%new -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (context == TabBarHeightObservationContext) { +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + if (context == DYYYTabBarHeightContext) { + __weak __typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ - [self setNeedsLayout]; + __strong __typeof(weakSelf) strongSelf = weakSelf; + if (strongSelf) { + NSLog(@"[DYYY] observeValueForKeyPath: %@ has new value: '%@'", kDYYYTabBarHeightKey, change[NSKeyValueChangeNewKey]); + if (originalTabBarHeight == kInvalidHeight) { + [strongSelf initializeOriginalTabBarHeight]; + } + [strongSelf calculateTabBarHeight]; + [strongSelf applyTabBarHeight]; + } }); } } +- (void)didMoveToWindow { + %orig; + if (self.window) { + [self initializeOriginalTabBarHeight]; + [self calculateTabBarHeight]; + } +} + - (void)layoutSubviews { %orig; - if (originalTabHeight == 0) { - NSString *sourceDescription = @""; - if (self.frame.size.height > 30) { - originalTabHeight = self.frame.size.height; - sourceDescription = [NSString stringWithFormat:@"from self.frame.size.height: %.1f", originalTabHeight]; - } else { - CGFloat bottomInset = (self.window ?: [DYYYUtils getActiveWindow]).safeAreaInsets.bottom; - originalTabHeight = 49 + bottomInset; - sourceDescription = [NSString stringWithFormat:@"by fallback calculation: 49.0 + %.1f", bottomInset]; - } - NSLog(@"[DYYY] Initialized originalTabHeight: %.1f (%@)", originalTabHeight, sourceDescription); + if (originalTabBarHeight == kInvalidHeight) { + NSLog(@"[DYYY] layoutSubviews: Fallback! originalTabBarHeight initialization triggered."); + [self initializeOriginalTabBarHeight]; } - CGFloat customHeight = DYYYGetFloat(@"DYYYTabBarHeight"); - tabHeight = (customHeight > 0) ? customHeight : originalTabHeight; + if (gCurrentTabBarHeight == kInvalidHeight) { + NSLog(@"[DYYY] layoutSubviews: Fallback! gCurrentTabBarHeight calculation triggered."); + [self calculateTabBarHeight]; + } - if (tabHeight <= 0) + if ([self applyTabBarHeight]) return; - if (fabs(self.frame.size.height - tabHeight) > 0.1) { - NSLog(@"[DYYY] Adjusting tabHeight to: %1f", tabHeight); - - if ([self respondsToSelector:@selector(setDesiredHeight:)]) { - ((void (*)(id, SEL, double))objc_msgSend)(self, @selector(setDesiredHeight:), tabHeight); - } - - CGRect frame = self.frame; - frame.size.height = tabHeight; - if (self.superview) { - frame.origin.y = self.superview.bounds.size.height - tabHeight; - } - self.frame = frame; - return; - } - BOOL hideShop = DYYYGetBool(@"DYYYHideShopButton"); BOOL hideMsg = DYYYGetBool(@"DYYYHideMessageButton"); BOOL hideFri = DYYYGetBool(@"DYYYHideFriendsButton"); @@ -5096,7 +5185,7 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; continue; } // 隐藏底栏背景 - if ([subview isKindOfClass:barBackgroundClass] || ([subview isMemberOfClass:[UIView class]] && originalTabHeight > 0 && fabs(subview.frame.size.height - tabHeight) < 0.1)) { + if ([subview isKindOfClass:barBackgroundClass] || ([subview isMemberOfClass:[UIView class]] && originalTabBarHeight > 0 && fabs(subview.frame.size.height - gCurrentTabBarHeight) < 0.1)) { subview.hidden = shouldHideBackgrounds; } // 隐藏细分割线 @@ -5120,60 +5209,59 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; - (void)setHidden:(BOOL)hidden { %orig(hidden); - // 禁用首页刷新功能 - if (DYYYGetBool(@"DYYYDisableHomeRefresh")) { - for (UIView *subview in self.subviews) { - if ([subview isKindOfClass:generalButtonClass]) { - AWENormalModeTabBarGeneralButton *button = (AWENormalModeTabBarGeneralButton *)subview; + BOOL disableHomeRefresh = DYYYGetBool(@"DYYYDisableHomeRefresh"); + BOOL enableFullScreen = DYYYGetBool(@"DYYYEnableFullScreen"); + BOOL hideBottomBg = DYYYGetBool(@"DYYYHideBottomBg"); + BOOL hideFriendsButton = DYYYGetBool(@"DYYYHideFriendsButton"); + + BOOL isHomeSelected = NO; + BOOL isFriendsSelected = NO; + + for (UIView *subview in self.subviews) { + if ([subview isKindOfClass:generalButtonClass]) { + AWENormalModeTabBarGeneralButton *button = (AWENormalModeTabBarGeneralButton *)subview; + + // 禁用首页刷新功能 + if (disableHomeRefresh && [button.accessibilityLabel isEqualToString:@"首页"]) { + button.userInteractionEnabled = (button.status != 2); + } + + // 检查当前选中的页 + if (enableFullScreen && button.status == 2) { if ([button.accessibilityLabel isEqualToString:@"首页"]) { - // status == 2 表示选中状态 - button.userInteractionEnabled = (button.status != 2); + isHomeSelected = YES; + } else if ([button.accessibilityLabel containsString:@"朋友"]) { + isFriendsSelected = YES; } } } } - // 背景和分隔线处理 - BOOL hideBottomBg = DYYYGetBool(@"DYYYHideBottomBg"); - BOOL enableFullScreen = DYYYGetBool(@"DYYYEnableFullScreen"); - if (hideBottomBg || enableFullScreen) { if (self.skinContainerView) { self.skinContainerView.hidden = YES; } - BOOL isHomeSelected = NO; - BOOL isFriendsSelected = NO; - - if (enableFullScreen && !hideBottomBg) { - for (UIView *subview in self.subviews) { - if ([subview isKindOfClass:generalButtonClass]) { - AWENormalModeTabBarGeneralButton *button = (AWENormalModeTabBarGeneralButton *)subview; - if (button.status == 2) { - if ([button.accessibilityLabel isEqualToString:@"首页"]) - isHomeSelected = YES; - else if ([button.accessibilityLabel containsString:@"朋友"]) - isFriendsSelected = YES; - } - } - } + BOOL shouldHideBackgrounds = NO; + if (hideBottomBg) { + shouldHideBackgrounds = YES; + } else if (enableFullScreen) { + shouldHideBackgrounds = isHomeSelected || (isFriendsSelected && !hideFriendsButton); } - BOOL hideFriendsButton = DYYYGetBool(@"DYYYHideFriendsButton"); - BOOL shouldHideBackgrounds = hideBottomBg || (enableFullScreen && (isHomeSelected || (isFriendsSelected && !hideFriendsButton))); - - // 单次遍历处理所有背景和分割线 + // 处理所有背景和分割线 for (UIView *subview in self.subviews) { + CGFloat subviewHeight = subview.frame.size.height; // 跳过底栏按钮 if ([subview isKindOfClass:generalButtonClass] || [subview isKindOfClass:plusButtonClass]) { continue; } // 隐藏底栏背景 - if ([subview isKindOfClass:barBackgroundClass] || ([subview isMemberOfClass:[UIView class]] && originalTabHeight > 0 && fabs(subview.frame.size.height - tabHeight) < 0.1)) { + if ([subview isKindOfClass:barBackgroundClass] || ([subview isMemberOfClass:[UIView class]] && originalTabBarHeight > 0 && fabs(subviewHeight - gCurrentTabBarHeight) < 0.1)) { subview.hidden = shouldHideBackgrounds; } // 隐藏细分割线 - if (subview.frame.size.height > 0 && subview.frame.size.height < 1 && subview.frame.size.width > 300) { + if (subviewHeight > 0 && subviewHeight < 1 && subview.frame.size.width > 300) { subview.hidden = enableFullScreen; } } @@ -5181,7 +5269,6 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; if (self.skinContainerView) { self.skinContainerView.hidden = NO; } - for (UIView *subview in self.subviews) { if ([subview isKindOfClass:barBackgroundClass] || [subview isMemberOfClass:[UIView class]]) { subview.hidden = NO; @@ -5441,10 +5528,10 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; - (void)layoutSubviews { %orig; - if (DYYYGetBool(@"DYYYEnableFullScreen") && tabHeight > 0) { + if (DYYYGetBool(@"DYYYEnableFullScreen") && gCurrentTabBarHeight > 0) { for (UIView *subview in self.subviews) { CGRect frame = subview.frame; - frame.origin.y -= tabHeight; + frame.origin.y -= gCurrentTabBarHeight; subview.frame = frame; } } @@ -5460,7 +5547,7 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; return; } - CGAffineTransform newTransform = CGAffineTransformMakeTranslation(0, originalTabHeight - tabHeight); + CGAffineTransform newTransform = CGAffineTransformMakeTranslation(0, originalTabBarHeight - gCurrentTabBarHeight); if (!CGAffineTransformEqualToTransform(self.transform, newTransform)) { self.transform = newTransform; @@ -5589,6 +5676,7 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; %end %hook UIView + - (id)initWithFrame:(CGRect)frame { UIView *view = %orig; if (hideButton && hideButton.isElementsHidden) { @@ -5610,11 +5698,12 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; } return view; } + - (void)layoutSubviews { %orig; if (DYYYGetBool(@"DYYYEnableFullScreen")) { - if (self.frame.size.height == originalTabHeight && originalTabHeight > 0) { + if (self.frame.size.height == originalTabBarHeight && originalTabBarHeight > 0) { UIViewController *vc = [DYYYUtils firstAvailableViewControllerFromView:self]; if ([vc isKindOfClass:NSClassFromString(@"AWEMixVideoPanelDetailTableViewController")] || [vc isKindOfClass:NSClassFromString(@"AWECommentInputViewController")] || [vc isKindOfClass:NSClassFromString(@"AWEAwemeDetailTableViewController")]) { @@ -5665,11 +5754,28 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; %orig(frame); return; } - CGRect superF = self.superview.frame; - if (CGRectGetHeight(superF) > 0 && CGRectGetHeight(frame) > 0 && CGRectGetHeight(frame) < CGRectGetHeight(superF)) { - CGFloat diff = CGRectGetHeight(superF) - CGRectGetHeight(frame); - if (fabs(diff - tabHeight) < 1.0) { - frame.size.height = CGRectGetHeight(superF); + + if (fabs(frame.origin.x) > 0.1 || fabs(frame.origin.y) > 0.1) { + %orig(frame); + return; + } + + UIView *superView = self.superview; + if (!superView) { + %orig(frame); + return; + } + + CGFloat superHeight = CGRectGetHeight(superView.bounds); + CGFloat frameHeight = CGRectGetHeight(frame); + CGFloat frameWidth = CGRectGetWidth(frame); + + if (superHeight > 0 && frameHeight > 0 && frameHeight < superHeight) { + CGFloat diff = superHeight - frameHeight; + BOOL isLandscapeFrame = (frameWidth > frameHeight); + + if (!isLandscapeFrame && fabs(diff - gCurrentTabBarHeight) < 1.0) { + frame.size.height = superHeight; } } @@ -5679,6 +5785,23 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; %orig(frame); } +%new +- (void)dyyy_applyGlobalTransparency { + if ([NSThread isMainThread]) { + if (self.window && self.tag != DYYY_IGNORE_GLOBAL_ALPHA_TAG) { + if (gGlobalTransparency != kInvalidAlpha && fabs(self.alpha - gGlobalTransparency) >= 0.01) { + [UIView animateWithDuration:0.2 animations:^{ + self.alpha = gGlobalTransparency; + }]; + } + } + } else { + dispatch_async(dispatch_get_main_queue(), ^{ + [self dyyy_applyGlobalTransparency]; + }); + } +} + %end %hook AWEIMSkylightListView @@ -5692,43 +5815,6 @@ static void *TabBarHeightObservationContext = &TabBarHeightObservationContext; } %end -static NSArray *kStackViewClasses = @[ NSClassFromString(@"AWEElementStackView"), NSClassFromString(@"IESLiveStackView") ]; -static char kCachedStackViewsKey; - -void applyGlobalTransparency(id targetObject) { - if (!targetObject) { - return; - } - - NSString *transparentValue = DYYYGetString(@"DYYYGlobalTransparency"); - NSScanner *scanner = [NSScanner scannerWithString:transparentValue]; - float alphaValue; - if (![scanner scanFloat:&alphaValue] || !scanner.isAtEnd || alphaValue < 0 || alphaValue > 1) { - return; - } - - NSHashTable *cachedStackViews = objc_getAssociatedObject(targetObject, &kCachedStackViewsKey); - if (!cachedStackViews) { - cachedStackViews = [NSHashTable weakObjectsHashTable]; - objc_setAssociatedObject(targetObject, &kCachedStackViewsKey, cachedStackViews, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - - for (Class stackViewClass in kStackViewClasses) { - NSArray *foundViews = [DYYYUtils findAllSubviewsOfClass:stackViewClass inContainer:targetObject]; - for (UIView *view in foundViews) { - [cachedStackViews addObject:view]; - } - } - } - - if (cachedStackViews.count > 0) { - for (UIView *stackViews in cachedStackViews) { - if (stackViews.alpha > 0 && fabs(stackViews.alpha - alphaValue) > 0.01 && stackViews.tag != DYYY_IGNORE_GLOBAL_ALPHA_TAG) { - stackViews.alpha = alphaValue; - } - } - } -} - %hook AFDPureModePageTapController - (void)onVideoPlayerViewDoubleClicked:(id)arg1 { @@ -5760,8 +5846,6 @@ void applyGlobalTransparency(id targetObject) { - (void)viewDidLayoutSubviews { %orig; - applyGlobalTransparency(self); - if (isFloatSpeedButtonEnabled) { BOOL hasRightStack = NO; Class stackClass = NSClassFromString(@"AWEElementStackView"); @@ -5869,7 +5953,7 @@ void applyGlobalTransparency(id targetObject) { if (useFullHeight) { frame.size.height = superviewHeight; } else { - frame.size.height = superviewHeight - tabHeight; + frame.size.height = superviewHeight - gCurrentTabBarHeight; } if (fabs(frame.size.height - self.view.frame.size.height) > 0.5) { @@ -6046,11 +6130,11 @@ void applyGlobalTransparency(id targetObject) { CGRect frame = contentView.frame; CGFloat parentHeight = contentView.superview.frame.size.height; - if (frame.size.height == parentHeight - tabHeight) { + if (frame.size.height == parentHeight - gCurrentTabBarHeight) { frame.size.height = parentHeight; contentView.frame = frame; - } else if (frame.size.height == parentHeight - (tabHeight * 2)) { - frame.size.height = parentHeight - tabHeight; + } else if (frame.size.height == parentHeight - (gCurrentTabBarHeight * 2)) { + frame.size.height = parentHeight - gCurrentTabBarHeight; contentView.frame = frame; } } @@ -6111,14 +6195,14 @@ void applyGlobalTransparency(id targetObject) { CGRect frame = self.frame; frame.size.height = self.superview.frame.size.height; self.frame = frame; - } else if (tabHeight > 0) { + } else if (gCurrentTabBarHeight > 0) { UIWindow *keyWindow = [DYYYUtils getActiveWindow]; if (keyWindow && keyWindow.safeAreaInsets.bottom == 0) { return; } CGRect frame = self.frame; - frame.size.height = self.superview.frame.size.height - tabHeight; + frame.size.height = self.superview.frame.size.height - gCurrentTabBarHeight; self.frame = frame; } } @@ -6216,6 +6300,7 @@ static id dyyyWindowKeyObserverToken = nil; static id dyyyDidBecomeActiveToken = nil; static id dyyyWillResignActiveToken = nil; static id dyyyKeyboardWillShowToken = nil; +static void *DYYYGlobalTransparencyContext = &DYYYGlobalTransparencyContext; static void DYYYRemoveAppLifecycleObservers(void) { NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; @@ -6241,10 +6326,18 @@ static void DYYYRemoveKeyboardObserver(void) { } %hook AppDelegate + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { BOOL result = %orig; initTargetClassNames(); + updateGlobalTransparencyCache(); + + [[NSUserDefaults standardUserDefaults] addObserver:(NSObject *)self + forKeyPath:kDYYYGlobalTransparencyKey + options:NSKeyValueObservingOptionNew + context:DYYYGlobalTransparencyContext]; + BOOL isEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"DYYYEnableFloatClearButton"]; if (isEnabled) { if (hideButton) { @@ -6308,36 +6401,28 @@ static void DYYYRemoveKeyboardObserver(void) { - (void)dealloc { DYYYRemoveAppLifecycleObservers(); DYYYRemoveKeyboardObserver(); + @try { + [[NSUserDefaults standardUserDefaults] removeObserver:(NSObject *)self + forKeyPath:kDYYYGlobalTransparencyKey + context:DYYYGlobalTransparencyContext]; + } @catch (NSException *exception) { + NSLog(@"[DYYY] KVO removeObserver failed: %@", exception); + } %orig; } -%end - -%hook AWELiveNewPreStreamViewController - -- (void)viewDidLayoutSubviews { - %orig; - - applyGlobalTransparency(self); -} -%end - -%hook AWECommentInputViewController - -- (void)viewDidLayoutSubviews { - %orig; - - applyGlobalTransparency(self); -} - -%end - -%hook AWEAwemeDetailNaviBarContainerView - -- (void)layoutSubviews { - %orig; - - applyGlobalTransparency(self); +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + if (context == DYYYGlobalTransparencyContext) { + dispatch_async(dispatch_get_main_queue(), ^{ + updateGlobalTransparencyCache(); + [[NSNotificationCenter defaultCenter] postNotificationName:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + }); + } else { + %orig(keyPath, object, change, context); + } } %end @@ -6392,19 +6477,20 @@ static Class TagViewClass = nil; }]; } return; - } else { - if (pureModeTimer) { - [pureModeTimer cancel]; - pureModeTimer = nil; - } - attempts = 0; - pureModeSet = NO; - %orig(alpha); } + // 清理纯净模式的残留状态 + if (pureModeTimer) { + [pureModeTimer cancel]; + pureModeTimer = nil; + } + attempts = 0; + pureModeSet = NO; + // 倍速和清屏按钮的状态控制 if (speedButton && isFloatSpeedButtonEnabled) { if (alpha == 0) { + dyyyCommentViewVisible = YES; } else if (alpha == 1) { dyyyCommentViewVisible = NO; } @@ -6412,19 +6498,14 @@ static Class TagViewClass = nil; updateClearButtonVisibility(); } - // 全局透明 + // 值守全局透明度 CGFloat finalAlpha = alpha; - if (alpha > 0 && self.tag != DYYY_IGNORE_GLOBAL_ALPHA_TAG) { - NSString *transparentValue = DYYYGetString(@"DYYYGlobalTransparency"); - NSScanner *scanner = [NSScanner scannerWithString:transparentValue]; - float alphaValue; - - if ([scanner scanFloat:&alphaValue] && scanner.isAtEnd && alphaValue >= 0 && alphaValue <= 1) { - finalAlpha = alphaValue; - } + if (alpha > 0 && self.tag != DYYY_IGNORE_GLOBAL_ALPHA_TAG && gGlobalTransparency != kInvalidAlpha) { + finalAlpha = gGlobalTransparency; } - if (fabs(self.alpha - finalAlpha) > 0.01) { + // 统一应用透明度 + if (fabs(self.alpha - finalAlpha) >= 0.01) { %orig(finalAlpha); } } @@ -6449,6 +6530,21 @@ static Class TagViewClass = nil; updateClearButtonVisibility(); } +- (void)didMoveToWindow { + %orig; + if (self.window) { + [self dyyy_applyGlobalTransparency]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dyyy_applyGlobalTransparency) name:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + } else { + [[NSNotificationCenter defaultCenter] removeObserver:self name:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + } +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + %orig; +} + - (void)layoutSubviews { %orig; @@ -6467,9 +6563,9 @@ static Class TagViewClass = nil; CGFloat targetHeight, tx, ty = 0; UIWindow *keyWindow = [DYYYUtils getActiveWindow]; if (keyWindow && keyWindow.safeAreaInsets.bottom == 0) { - targetHeight = tabHeight - originalTabHeight; + targetHeight = gCurrentTabBarHeight - originalTabBarHeight; } else { - targetHeight = tabHeight; + targetHeight = gCurrentTabBarHeight; } if ([DYYYUtils containsSubviewOfClass:GuideViewClass inContainer:self]) { @@ -6588,7 +6684,6 @@ static Class TagViewClass = nil; } - (void)setAlpha:(CGFloat)alpha { - %orig; if (speedButton && isFloatSpeedButtonEnabled) { if (alpha == 0) { dyyyCommentViewVisible = YES; @@ -6598,6 +6693,30 @@ static Class TagViewClass = nil; updateSpeedButtonVisibility(); updateClearButtonVisibility(); } + + CGFloat finalAlpha = alpha; + if (alpha > 0 && self.tag != DYYY_IGNORE_GLOBAL_ALPHA_TAG && gGlobalTransparency != kInvalidAlpha) { + finalAlpha = gGlobalTransparency; + } + + if (fabs(self.alpha - finalAlpha) >= 0.01) { + %orig(finalAlpha); + } +} + +- (void)didMoveToWindow { + %orig; + if (self.window) { + [self dyyy_applyGlobalTransparency]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dyyy_applyGlobalTransparency) name:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + } else { + [[NSNotificationCenter defaultCenter] removeObserver:self name:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + } +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + %orig; } - (void)layoutSubviews { @@ -6618,9 +6737,9 @@ static Class TagViewClass = nil; CGFloat targetHeight, tx, ty = 0; UIWindow *keyWindow = [DYYYUtils getActiveWindow]; if (keyWindow && keyWindow.safeAreaInsets.bottom == 0) { - targetHeight = tabHeight - originalTabHeight; + targetHeight = gCurrentTabBarHeight - originalTabBarHeight; } else { - targetHeight = tabHeight; + targetHeight = gCurrentTabBarHeight; } if ([DYYYUtils containsSubviewOfClass:GuideViewClass inContainer:self]) { @@ -6690,7 +6809,7 @@ static Class TagViewClass = nil; CGRect frame = subview.frame; if (DYYYGetBool(@"DYYYEnableFullScreen")) { - frame.size.height = subview.superview.frame.size.height - tabHeight; + frame.size.height = subview.superview.frame.size.height - gCurrentTabBarHeight; subview.frame = frame; } } @@ -6710,7 +6829,7 @@ static Class TagViewClass = nil; if (isWorkImage) { // 修复作者主页作品图片上移问题 CGRect frame = subview.frame; - frame.origin.y += tabHeight; + frame.origin.y += gCurrentTabBarHeight; subview.frame = frame; } } @@ -6751,7 +6870,7 @@ static Class TagViewClass = nil; - (void)setCenter:(CGPoint)center { UIViewController *vc = [DYYYUtils firstAvailableViewControllerFromView:self]; if ([vc isKindOfClass:NSClassFromString(@"AWEFeedPlayControlImpl.PureModePageCellViewController")] && DYYYGetBool(@"DYYYEnableFullScreen")) { - center.y -= tabHeight; + center.y -= gCurrentTabBarHeight; } %orig(center); } @@ -6769,6 +6888,39 @@ static Class TagViewClass = nil; %end %hook AWELandscapeFeedEntryView +- (void)setCenter:(CGPoint)center { + if (DYYYGetBool(@"DYYYEnableFullScreen")) { + center.y += gCurrentTabBarHeight * 0.5; + } + + %orig(center); +} + +- (void)setAlpha:(CGFloat)alpha { + CGFloat finalAlpha = alpha; + if (alpha > 0 && self.tag != DYYY_IGNORE_GLOBAL_ALPHA_TAG && gGlobalTransparency != kInvalidAlpha) { + finalAlpha = gGlobalTransparency; + } + + if (fabs(self.alpha - finalAlpha) >= 0.01) { + %orig(finalAlpha); + } +} + +- (void)didMoveToWindow { + %orig; + if (self.window) { + [self dyyy_applyGlobalTransparency]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dyyy_applyGlobalTransparency) name:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + } else { + [[NSNotificationCenter defaultCenter] removeObserver:self name:kDYYYGlobalTransparencyDidChangeNotification object:nil]; + } +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + %orig; +} - (void)layoutSubviews { %orig; @@ -6814,8 +6966,8 @@ static Class TagViewClass = nil; - (void)setFrame:(CGRect)frame { if (DYYYGetBool(@"DYYYEnableFullScreen")) { - CGFloat targetY = frame.origin.y - tabHeight; - CGFloat screenHeightMinusGDiff = [UIScreen mainScreen].bounds.size.height - tabHeight; + CGFloat targetY = frame.origin.y - gCurrentTabBarHeight; + CGFloat screenHeightMinusGDiff = [UIScreen mainScreen].bounds.size.height - gCurrentTabBarHeight; CGFloat tolerance = 10.0; @@ -6861,7 +7013,7 @@ static Class TagViewClass = nil; } } if (target) { - target.hidden = ([(UIView *)self frame].size.height == tabHeight); + target.hidden = ([(UIView *)self frame].size.height == gCurrentTabBarHeight); } } }