Skip to content

Commit bcc301b

Browse files
committed
添加全屏模式下的视图调整逻辑,优化横屏视频显示效果
1 parent 0470d3f commit bcc301b

File tree

1 file changed

+92
-7
lines changed

1 file changed

+92
-7
lines changed

DYYY.xm

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Channel: @huamidev
66
// Created on: 2024/10/04
77
//
8+
#import <QuartzCore/QuartzCore.h>
89
#import <UIKit/UIKit.h>
910
#import <float.h>
1011
#import <math.h>
@@ -22,6 +23,8 @@
2223
#import "DYYYToast.h"
2324
#import "DYYYUtils.h"
2425

26+
static CGFloat DYYYCurrentTabHeight(void);
27+
2528
static NSDictionary<NSString *, NSString *> *DYYYTopTabTitleMapping(void) {
2629
static NSString *cachedRawValue = nil;
2730
static NSDictionary<NSString *, NSString *> *cachedMapping = nil;
@@ -4242,6 +4245,83 @@ static NSHashTable *processedParentViews = nil;
42424245
}
42434246
%end
42444247

4248+
static BOOL DYYYIsLandscapeVideoBounds(CGSize size) {
4249+
if (size.width <= 0.0f || size.height <= 0.0f) {
4250+
return NO;
4251+
}
4252+
if (size.width <= size.height) {
4253+
return NO;
4254+
}
4255+
const CGFloat referenceAspect = 414.0f / 232.875f;
4256+
const CGFloat tolerance = 0.5f;
4257+
CGFloat aspectRatio = size.width / size.height;
4258+
return aspectRatio >= (referenceAspect - tolerance);
4259+
}
4260+
4261+
static char kDYYYMTKViewShiftAppliedOffsetKey;
4262+
4263+
static void DYYYResetMTKViewShiftState(UIView *view) {
4264+
if (!view) {
4265+
return;
4266+
}
4267+
objc_setAssociatedObject(view, &kDYYYMTKViewShiftAppliedOffsetKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4268+
}
4269+
4270+
static CGFloat DYYYDesiredMTKViewShiftOffset(UIView *view) {
4271+
if (!view || !view.superview) {
4272+
return 0.0f;
4273+
}
4274+
if (!DYYYGetBool(@"DYYYEnableFullScreen")) {
4275+
return 0.0f;
4276+
}
4277+
if (!DYYYIsLandscapeVideoBounds(view.bounds.size)) {
4278+
return 0.0f;
4279+
}
4280+
CGFloat tabHeight = DYYYCurrentTabHeight();
4281+
if (tabHeight <= 0.0f) {
4282+
return 0.0f;
4283+
}
4284+
return tabHeight * 0.5f;
4285+
}
4286+
4287+
static void DYYYApplyMTKViewShiftIfNeeded(UIView *view) {
4288+
if (!view) {
4289+
return;
4290+
}
4291+
4292+
NSNumber *storedValue = objc_getAssociatedObject(view, &kDYYYMTKViewShiftAppliedOffsetKey);
4293+
if (!view.superview) {
4294+
if (storedValue) {
4295+
objc_setAssociatedObject(view, &kDYYYMTKViewShiftAppliedOffsetKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4296+
}
4297+
return;
4298+
}
4299+
4300+
CGFloat desiredOffset = DYYYDesiredMTKViewShiftOffset(view);
4301+
CGFloat appliedOffset = storedValue ? storedValue.doubleValue : 0.0f;
4302+
CGFloat delta = desiredOffset - appliedOffset;
4303+
if (fabs(delta) < 0.1f) {
4304+
if (desiredOffset <= 0.0f && storedValue) {
4305+
objc_setAssociatedObject(view, &kDYYYMTKViewShiftAppliedOffsetKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4306+
}
4307+
return;
4308+
}
4309+
4310+
CGPoint position = view.layer.position;
4311+
position.y -= delta;
4312+
4313+
[CATransaction begin];
4314+
[CATransaction setDisableActions:YES];
4315+
view.layer.position = position;
4316+
[CATransaction commit];
4317+
4318+
if (desiredOffset > 0.0f) {
4319+
objc_setAssociatedObject(view, &kDYYYMTKViewShiftAppliedOffsetKey, @(desiredOffset), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4320+
} else {
4321+
objc_setAssociatedObject(view, &kDYYYMTKViewShiftAppliedOffsetKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4322+
}
4323+
}
4324+
42454325
%hook MTKView
42464326

42474327
- (void)layoutSubviews {
@@ -4259,6 +4339,16 @@ static NSHashTable *processedParentViews = nil;
42594339
}
42604340
}
42614341

4342+
- (void)setFrame:(CGRect)frame {
4343+
UIViewController *vc = [DYYYUtils firstAvailableViewControllerFromView:self];
4344+
Class playVCClass = NSClassFromString(@"AWEPlayVideoViewController");
4345+
DYYYResetMTKViewShiftState(self);
4346+
%orig(frame);
4347+
if (vc && playVCClass && [vc isKindOfClass:playVCClass]) {
4348+
DYYYApplyMTKViewShiftIfNeeded(self);
4349+
}
4350+
}
4351+
42624352
%end
42634353

42644354
// 拦截开屏广告
@@ -4806,6 +4896,8 @@ static NSHashTable *processedParentViews = nil;
48064896
static CGFloat tabHeight = 0;
48074897
static CGFloat originalTabHeight = 0;
48084898

4899+
static CGFloat DYYYCurrentTabHeight(void) { return tabHeight; }
4900+
48094901
%hook AWENormalModeTabBar
48104902

48114903
static Class barBackgroundClass = nil;
@@ -6647,13 +6739,6 @@ static Class TagViewClass = nil;
66476739
%end
66486740

66496741
%hook AWELandscapeFeedEntryView
6650-
- (void)setCenter:(CGPoint)center {
6651-
if (DYYYGetBool(@"DYYYEnableFullScreen")) {
6652-
center.y += tabHeight * 0.5;
6653-
}
6654-
6655-
%orig(center);
6656-
}
66576742

66586743
- (void)layoutSubviews {
66596744
%orig;

0 commit comments

Comments
 (0)