Skip to content

Commit 9ce8000

Browse files
committed
加入长按上下控制倍速
1 parent a01c739 commit 9ce8000

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

DYYY.xm

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,9 @@ static NSArray<NSString *> *dyyy_qualityRank = nil;
19881988
%hook AWEPlayInteractionSpeedController
19891989

19901990
static BOOL hasChangedSpeed = NO;
1991+
static CGFloat currentLongPressSpeed = 0;
1992+
static CGFloat initialTouchX = 0;
1993+
static BOOL isGestureActive = NO;
19911994

19921995
- (CGFloat)longPressFastSpeedValue {
19931996
float longPressSpeed = DYYYGetFloat(@"DYYYLongPressSpeed");
@@ -2000,6 +2003,11 @@ static BOOL hasChangedSpeed = NO;
20002003
- (void)changeSpeed:(double)speed {
20012004
float longPressSpeed = DYYYGetFloat(@"DYYYLongPressSpeed");
20022005

2006+
if (isGestureActive && currentLongPressSpeed > 0) {
2007+
%orig(currentLongPressSpeed);
2008+
return;
2009+
}
2010+
20032011
if (speed == 2.0) {
20042012
if (!hasChangedSpeed) {
20052013
if (longPressSpeed != 0 && longPressSpeed != 2.0) {
@@ -2020,6 +2028,52 @@ static BOOL hasChangedSpeed = NO;
20202028
}
20212029
}
20222030

2031+
- (void)handleLongPressFastSpeed:(UILongPressGestureRecognizer *)gesture {
2032+
%orig;
2033+
2034+
if (!DYYYGetBool(@"DYYYEnableLongPressSpeedGesture")) {
2035+
return;
2036+
}
2037+
2038+
CGPoint location = [gesture locationInView:gesture.view];
2039+
2040+
static CGFloat initialTouchY = 0;
2041+
2042+
if (gesture.state == UIGestureRecognizerStateBegan) {
2043+
initialTouchY = location.y;
2044+
isGestureActive = YES;
2045+
2046+
float longPressSpeed = DYYYGetFloat(@"DYYYLongPressSpeed");
2047+
if (longPressSpeed == 0) {
2048+
longPressSpeed = 2.0;
2049+
}
2050+
currentLongPressSpeed = longPressSpeed;
2051+
}
2052+
else if (gesture.state == UIGestureRecognizerStateChanged && isGestureActive) {
2053+
CGFloat deltaY = location.y - initialTouchY;
2054+
CGFloat threshold = 10.0;
2055+
2056+
if (fabs(deltaY) > threshold) {
2057+
CGFloat speedChange;
2058+
speedChange = (deltaY > 0) ? 0.25 : -0.25;
2059+
2060+
CGFloat newSpeed = currentLongPressSpeed + speedChange;
2061+
newSpeed = MAX(0.5, MIN(3.0, newSpeed));
2062+
2063+
if (newSpeed != currentLongPressSpeed) {
2064+
currentLongPressSpeed = newSpeed;
2065+
initialTouchY = location.y;
2066+
[self changeSpeed:currentLongPressSpeed];
2067+
}
2068+
}
2069+
}
2070+
else if (gesture.state == UIGestureRecognizerStateEnded ||
2071+
gesture.state == UIGestureRecognizerStateCancelled) {
2072+
isGestureActive = NO;
2073+
currentLongPressSpeed = 0;
2074+
initialTouchY = 0;
2075+
}
2076+
}
20232077
%end
20242078

20252079
%hook UILabel
@@ -2028,12 +2082,12 @@ static BOOL hasChangedSpeed = NO;
20282082
UIView *superview = self.superview;
20292083

20302084
if ([superview isKindOfClass:%c(AFDFastSpeedView)] && text) {
2031-
float longPressSpeed = DYYYGetFloat(@"DYYYLongPressSpeed");
2032-
if (longPressSpeed == 0) {
2033-
longPressSpeed = 2.0;
2085+
CGFloat displaySpeed = isGestureActive && currentLongPressSpeed > 0 ? currentLongPressSpeed : DYYYGetFloat(@"DYYYLongPressSpeed");
2086+
if (displaySpeed == 0) {
2087+
displaySpeed = 2.0;
20342088
}
20352089

2036-
NSString *speedString = [NSString stringWithFormat:@"%.2f", longPressSpeed];
2090+
NSString *speedString = [NSString stringWithFormat:@"%.2f", displaySpeed];
20372091
if ([speedString hasSuffix:@".00"]) {
20382092
speedString = [speedString substringToIndex:speedString.length - 3];
20392093
} else if ([speedString hasSuffix:@"0"] && [speedString containsString:@"."]) {

DYYYSettingViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ - (void)setupSettingItems {
136136
[DYYYSettingItem itemWithTitle:@"自定弹幕颜色" key:@"DYYYDanmuColor" type:DYYYSettingItemTypeTextField placeholder:@"十六进制"],
137137
[DYYYSettingItem itemWithTitle:@"设置默认倍速" key:@"DYYYDefaultSpeed" type:DYYYSettingItemTypePicker],
138138
[DYYYSettingItem itemWithTitle:@"设置长按倍速" key:@"DYYYLongPressSpeed" type:DYYYSettingItemTypePicker],
139+
[DYYYSettingItem itemWithTitle:@"上下控制倍速" key:@"DYYYEnableLongPressSpeedGesture" type:DYYYSettingItemTypeSwitch],
139140
[DYYYSettingItem itemWithTitle:@"显示进度时长" key:@"DYYYShowScheduleDisplay" type:DYYYSettingItemTypeSwitch],
140141
[DYYYSettingItem itemWithTitle:@"进度时长样式" key:@"DYYYScheduleStyle" type:DYYYSettingItemTypeTextField placeholder:@"默认"],
141142
[DYYYSettingItem itemWithTitle:@"进度纵轴位置" key:@"DYYYTimelineVerticalPosition" type:DYYYSettingItemTypeTextField placeholder:@"-12.5"],

DYYYSettings.xm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ void showDYYYSettingsVC(UIViewController *rootVC, BOOL hasAgreed) {
309309
@"detail" : @"",
310310
@"cellType" : @26,
311311
@"imageName" : @"ic_speed_outlined_20"},
312+
@{
313+
@"identifier" : @"DYYYEnableLongPressSpeedGesture",
314+
@"title" : @"启用长按倍速手势",
315+
@"subTitle" : @"长按时可通过上下滑动调整倍速",
316+
@"detail" : @"",
317+
@"cellType" : @37,
318+
@"imageName" : @"ic_speed_outlined_20"
319+
},
312320
@{@"identifier" : @"DYYYEnableArea",
313321
@"title" : @"时间属地显示",
314322
@"detail" : @"",

DYYYSettingsHelper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ + (void)addTapGestureToView:(UIView *)view target:(id)target {
707707
+ (void)showUserAgreementAlert {
708708
[self showTextInputAlert:@"用户协议"
709709
defaultText:@""
710-
placeholder:@""
710+
placeholder:@"我已阅读并同意继续使用"
711711
onConfirm:^(NSString *text) {
712712
if ([text isEqualToString:@"我已阅读并同意继续使用"]) {
713713
[self setUserDefaults:@"YES" forKey:@"DYYYUserAgreementAccepted"];

0 commit comments

Comments
 (0)