optimize relocating setting stacks to lowest point

This commit is contained in:
TrueZhuanjia committed 2025-06-05 23:48:53 +08:00
1 parent e5b1eda3a1
commit 7ed6c559e0
1 file changed
+26 -7
@@ -30,6 +30,7 @@
UIStackView *parentStack; UIStackView *parentStack;
NSMutableDictionary *_settingStackDict; NSMutableDictionary *_settingStackDict;
NSMutableArray *_favoriteSettingStackIdentifiers; NSMutableArray *_favoriteSettingStackIdentifiers;
bool settingStackWillBeRelocatedToLowestPosition;
uint8_t currentSettingsMenuMode; uint8_t currentSettingsMenuMode;
UIView *snapshot; UIView *snapshot;
UIStackView* capturedStack; UIStackView* capturedStack;
@@ -631,7 +632,7 @@ BOOL isCustomResolution(CGSize res) {
NSLog(@" index: %ld, stackY: %f, touchY: %f", (long)i, CGRectGetMidY(subview.frame), location.y); NSLog(@" index: %ld, stackY: %f, touchY: %f", (long)i, CGRectGetMidY(subview.frame), location.y);
if(stackMinY < location.y){ if(stackMinY < location.y){
NSLog(@"index: %ld", i); NSLog(@"index: %ld", i);
subview.backgroundColor = [ThemeManager appPrimaryColorWithAlpha]; //subview.backgroundColor = [ThemeManager appPrimaryColorWithAlpha];
return i; return i;
} }
} }
@@ -645,10 +646,22 @@ BOOL isCustomResolution(CGSize res) {
currentStack = parentStack.arrangedSubviews[i]; currentStack = parentStack.arrangedSubviews[i];
if(currentIndex == i){ if(currentIndex == i){
currentStack.layer.cornerRadius = 6; settingStackWillBeRelocatedToLowestPosition = false;
currentStack.layer.masksToBounds = YES; if(i == parentStack.arrangedSubviews.count-1 && locationInParentStack.y > CGRectGetMaxY(currentStack.frame)){
currentStack.clipsToBounds = YES; snapshot.layer.cornerRadius = 6;
currentStack.backgroundColor = [ThemeManager appPrimaryColorWithAlpha]; snapshot.layer.masksToBounds = YES;
snapshot.clipsToBounds = YES;
snapshot.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:0.35];
currentStack.backgroundColor = [UIColor clearColor];
settingStackWillBeRelocatedToLowestPosition = true;
}
else{
currentStack.layer.cornerRadius = 6;
currentStack.layer.masksToBounds = YES;
currentStack.clipsToBounds = YES;
currentStack.backgroundColor = [ThemeManager appPrimaryColorWithAlpha];
snapshot.backgroundColor = [UIColor clearColor];
}
} }
else{ else{
currentStack.layer.cornerRadius = 0; currentStack.layer.cornerRadius = 0;
@@ -732,6 +745,7 @@ BOOL isCustomResolution(CGSize res) {
break; break;
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateEnded:
// 更新快照视图位置 // 更新快照视图位置
// snapshot.center = CGPointMake(originalCenter.x, point.y); // snapshot.center = CGPointMake(originalCenter.x, point.y);
@@ -744,8 +758,14 @@ BOOL isCustomResolution(CGSize res) {
NSInteger oldIndex = [parentStack.arrangedSubviews indexOfObject:capturedStack]; NSInteger oldIndex = [parentStack.arrangedSubviews indexOfObject:capturedStack];
newIndex = newIndex > oldIndex ? newIndex - 1 : newIndex; newIndex = newIndex > oldIndex ? newIndex - 1 : newIndex;
//NSInteger newIndex = 1; //NSInteger newIndex = 1;
//NSLog(@"newidx %ld, oldidx %ld", newIndex, oldIndex);
if(settingStackWillBeRelocatedToLowestPosition){
newIndex = newIndex + 1;
settingStackWillBeRelocatedToLowestPosition = false;
}
if (newIndex != NSNotFound) { if (newIndex != NSNotFound) {
if(newIndex >= parentStack.arrangedSubviews.count) newIndex = parentStack.arrangedSubviews.count-1;
[parentStack removeArrangedSubview:capturedStack]; [parentStack removeArrangedSubview:capturedStack];
[parentStack insertArrangedSubview:capturedStack atIndex:newIndex]; [parentStack insertArrangedSubview:capturedStack atIndex:newIndex];
// [parentStack addSubview:capturedStack]; // [parentStack addSubview:capturedStack];
@@ -755,8 +775,6 @@ BOOL isCustomResolution(CGSize res) {
} }
// 移除快照视图,显示原始视图 // 移除快照视图,显示原始视图
break; break;
case UIGestureRecognizerStateCancelled:
break;
default:break; default:break;
} }
@@ -885,6 +903,7 @@ BOOL isCustomResolution(CGSize res) {
//[self updateTheme]; //[self updateTheme];
[UIView performWithoutAnimation:^{ [UIView performWithoutAnimation:^{
settingStackWillBeRelocatedToLowestPosition = false;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"]; [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];