highlighted background for long press setting stack

This commit is contained in:
TrueZhuanjia committed 2025-06-14 21:34:31 +08:00
1 parent 758a888a53
commit 5734a0a0b7
1 file changed
+37 -18
@@ -776,6 +776,21 @@ BOOL isCustomResolution(CGSize res) {
return 0; return 0;
} }
- (void)highlightedPurpleBackgroundForView:(UIView* )view{
view.layer.cornerRadius = 6;
view.layer.masksToBounds = YES;
view.clipsToBounds = YES;
view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:0.35];
}
- (void)highlightedBackgroundForView:(UIView* )view{
view.layer.cornerRadius = 6;
view.layer.masksToBounds = YES;
view.clipsToBounds = YES;
view.backgroundColor = [ThemeManager appPrimaryColorWithAlpha];
}
- (void)updateRelocationIndicatorFor:(CGPoint)locationInParentStack{ - (void)updateRelocationIndicatorFor:(CGPoint)locationInParentStack{
uint16_t currentIndex = [self parentStackIndexForLocation:locationInParentStack]; uint16_t currentIndex = [self parentStackIndexForLocation:locationInParentStack];
UIStackView* currentStack; UIStackView* currentStack;
@@ -785,18 +800,12 @@ BOOL isCustomResolution(CGSize res) {
if(currentIndex == i){ if(currentIndex == i){
settingStackWillBeRelocatedToLowestPosition = false; settingStackWillBeRelocatedToLowestPosition = false;
if(i == _parentStack.arrangedSubviews.count-1 && locationInParentStack.y > CGRectGetMaxY(currentStack.frame)){ if(i == _parentStack.arrangedSubviews.count-1 && locationInParentStack.y > CGRectGetMaxY(currentStack.frame)){
snapshot.layer.cornerRadius = 6; [self highlightedPurpleBackgroundForView:snapshot];
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]; currentStack.backgroundColor = [UIColor clearColor];
settingStackWillBeRelocatedToLowestPosition = true; settingStackWillBeRelocatedToLowestPosition = true;
} }
else{ else{
currentStack.layer.cornerRadius = 6; [self highlightedBackgroundForView:currentStack];
currentStack.layer.masksToBounds = YES;
currentStack.clipsToBounds = YES;
currentStack.backgroundColor = [ThemeManager appPrimaryColorWithAlpha];
snapshot.backgroundColor = [UIColor clearColor]; snapshot.backgroundColor = [UIColor clearColor];
} }
} }
@@ -817,6 +826,7 @@ BOOL isCustomResolution(CGSize res) {
- (void)findCapturedStackByTouchLocation:(CGPoint)point{ - (void)findCapturedStackByTouchLocation:(CGPoint)point{
UIView *touchedView = [_parentStack hitTest:point withEvent:nil]; UIView *touchedView = [_parentStack hitTest:point withEvent:nil];
while(touchedView){ while(touchedView){
NSLog(@"view captured: %@, %@", touchedView, touchedView.accessibilityIdentifier);
if([touchedView isKindOfClass:[UIStackView class]] && touchedView.accessibilityIdentifier != nil){ if([touchedView isKindOfClass:[UIStackView class]] && touchedView.accessibilityIdentifier != nil){
capturedStack = (UIStackView *)touchedView; capturedStack = (UIStackView *)touchedView;
break; break;
@@ -834,24 +844,32 @@ BOOL isCustomResolution(CGSize res) {
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) { handler:^(UIAlertAction * _Nonnull action) {
[self addSettingToFavorite:self->capturedStack]; [self addSettingToFavorite:self->capturedStack];
self->capturedStack.backgroundColor = [UIColor clearColor];
}]; }];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@""
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
self->capturedStack.backgroundColor = [UIColor clearColor];
}];
[actionSheet addAction:addFavoriteAction]; [actionSheet addAction:addFavoriteAction];
[actionSheet addAction:cancelAction];
return actionSheet; return actionSheet;
} }
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture { - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture {
CGPoint locationInParentStack = [gesture locationInView:_parentStack]; CGPoint locationInParentStack = [gesture locationInView:_parentStack];
CGPoint locationInRootView = [gesture locationInView:self.view.superview]; CGPoint locationInRootView = [gesture locationInView:self.view.superview];
if(currentSettingsMenuMode == AllSettings){ if(currentSettingsMenuMode == AllSettings &&gesture.state == UIGestureRecognizerStateBegan) {
if (gesture.state == UIGestureRecognizerStateBegan) { [self findCapturedStackByTouchLocation:locationInParentStack];
[self findCapturedStackByTouchLocation:locationInParentStack]; if(capturedStack == nil) return;
if(capturedStack == nil) return; [self highlightedBackgroundForView:capturedStack];
UIAlertController* actionSheet = [self prepareAddToFavoriteActionSheet]; UIAlertController* actionSheet = [self prepareAddToFavoriteActionSheet];
actionSheet.popoverPresentationController.sourceView = capturedStack; actionSheet.popoverPresentationController.sourceView = capturedStack;
[self presentViewController:actionSheet animated:YES completion:nil]; [self presentViewController:actionSheet animated:YES completion:nil];
}
} }
static CGPoint originalCenter; static CGPoint originalCenter;
static NSInteger originalIndex; static NSInteger originalIndex;
if(gesture.state == UIGestureRecognizerStateBegan){ if(gesture.state == UIGestureRecognizerStateBegan){
@@ -870,7 +888,8 @@ BOOL isCustomResolution(CGSize res) {
if(capturedStack == nil) return; if(capturedStack == nil) return;
snapshot = [capturedStack snapshotViewAfterScreenUpdates:YES]; snapshot = [capturedStack snapshotViewAfterScreenUpdates:YES];
snapshot.center = capturedStack.center; //snapshot.center = capturedStack.center;
snapshot.center = locationInParentStack;
[_parentStack addSubview:snapshot]; [_parentStack addSubview:snapshot];
capturedStack.hidden = YES; capturedStack.hidden = YES;
originalCenter = capturedStack.center; originalCenter = capturedStack.center;
@@ -878,7 +897,7 @@ BOOL isCustomResolution(CGSize res) {
break; break;
case UIGestureRecognizerStateChanged: case UIGestureRecognizerStateChanged:
snapshot.center = CGPointMake(locationInParentStack.x, locationInParentStack.y); snapshot.center = locationInParentStack;
// NSLog(@"coordY in rootView: %f", locationInRootView.y); // NSLog(@"coordY in rootView: %f", locationInRootView.y);
[self handleAutoScroll:locationInRootView]; [self handleAutoScroll:locationInRootView];
[self updateRelocationIndicatorFor:locationInParentStack]; [self updateRelocationIndicatorFor:locationInParentStack];