Skip to content

Commit

Permalink
feat: 圈选提示
Browse files Browse the repository at this point in the history
  • Loading branch information
styluo authored and YoloMao committed Nov 16, 2022
1 parent 8aac0ef commit a90c42d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 314 deletions.
2 changes: 0 additions & 2 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
34664587278EEEA6009C351C /* A0GrowingAnalyticsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 047BF3A224F638BB0028FE94 /* A0GrowingAnalyticsTest.m */; };
346EABE1277EDF8A00A32B03 /* EventTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 346EABE0277EDF8A00A32B03 /* EventTest.m */; };
346EABE5277EE1FD00A32B03 /* HybridTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 42ADE26B250B292900CA7268 /* HybridTest.m */; };
346EABE8277EE33F00A32B03 /* StatusBarEventManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 346EABE7277EE33F00A32B03 /* StatusBarEventManagerTest.m */; };
346EABEB277EE53200A32B03 /* DeviceInfoTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 346EABEA277EE53200A32B03 /* DeviceInfoTest.m */; };
346EABF2277EE63F00A32B03 /* NodeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 346EABF1277EE63F00A32B03 /* NodeTest.m */; };
34821C6727B247DB006C8B8E /* UISegmentedControlAutotrackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34821C6627B247DB006C8B8E /* UISegmentedControlAutotrackTest.m */; };
Expand Down Expand Up @@ -1718,7 +1717,6 @@
34BA7B23277C617F0030AC21 /* GrowingDispatchManagerTest.m in Sources */,
34B2148A2796A234004E2CE3 /* GrowingAlertTest.m in Sources */,
34BA7B27277C63070030AC21 /* EncryptionTest.m in Sources */,
346EABE8277EE33F00A32B03 /* StatusBarEventManagerTest.m in Sources */,
34BA7B26277C62FF0030AC21 /* JSONDatabaseTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down

This file was deleted.

43 changes: 0 additions & 43 deletions GrowingTrackerCore/Manager/GrowingStatusBarEventManager.h

This file was deleted.

87 changes: 0 additions & 87 deletions GrowingTrackerCore/Manager/GrowingStatusBarEventManager.m

This file was deleted.

114 changes: 80 additions & 34 deletions GrowingTrackerCore/Menu/GrowingStatusBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,103 @@

#import "GrowingTrackerCore/Menu/GrowingStatusBar.h"
#import "GrowingTrackerCore/Helpers/UIControl+GrowingHelper.h"
#import "GrowingTrackerCore/Manager/GrowingStatusBarEventManager.h"

@interface GrowingStatusBar () <GrowingStatusBarEventProtocol>
@interface GrowingStatusBar ()

@property (nonatomic, retain) UIControl * btn;
@property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer;

@end

@implementation GrowingStatusBar

- (UIPanGestureRecognizer *)panGestureRecognizer
{
if (!_panGestureRecognizer) {
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragViewMoved:)];
}
return _panGestureRecognizer;
}

- (void)dragViewMoved:(UIPanGestureRecognizer *)panGestureRecognizer
{
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [panGestureRecognizer translationInView:self];

double statusBarFrameHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;

bool topValid = (self.btn.frame.origin.y + translation.y) > statusBarFrameHeight;
bool bottomValid = (self.btn.frame.origin.y + translation.y) < (self.frame.size.height - self.btn.frame.size.height);
if (topValid && bottomValid) {
self.btn.center = CGPointMake(self.btn.center.x, self.btn.center.y + translation.y);
}

[panGestureRecognizer setTranslation:CGPointZero inView:self];
}
}

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
UILabel *label = [[UILabel alloc] init];
label.userInteractionEnabled = YES;
label.backgroundColor = [UIColor blueColor];
label.textColor = [UIColor whiteColor];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;
self.statusLable = label;
[self addSubview:label];

self.btn = [[UIControl alloc] init];
[label addSubview:self.btn];
self.btn.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.btn.growingHelper_onClick = self.onButtonClick;
UIControl *tipBtn = [[UIControl alloc] init];
tipBtn.backgroundColor = [UIColor colorWithRed:0.0 green:0.56 blue:1.0 alpha:1.0];

self.growingViewLevel = 0;
UILabel *tipLabel = [[UILabel alloc] init];
tipLabel.textColor = [UIColor whiteColor];
tipLabel.font = [UIFont systemFontOfSize:14];
tipLabel.textAlignment = NSTextAlignmentCenter;
UILabel *dragTipLabel = [[UILabel alloc] init];
dragTipLabel.textColor = [UIColor whiteColor];
dragTipLabel.font = [UIFont systemFontOfSize:12];
dragTipLabel.textAlignment = NSTextAlignmentRight;
dragTipLabel.text = @"如有遮挡请拖动此条";

[tipBtn addSubview:tipLabel];
[tipBtn addSubview:dragTipLabel];
[self addSubview:tipBtn];
tipLabel.translatesAutoresizingMaskIntoConstraints = NO;
dragTipLabel.translatesAutoresizingMaskIntoConstraints = NO;
tipBtn.translatesAutoresizingMaskIntoConstraints = NO;

if (@available(iOS 13.0, *)) {
[[GrowingStatusBarEventManager sharedInstance] addStatusBarObserver:self];
if (@available(iOS 11.0, *)) {
[NSLayoutConstraint activateConstraints:@[
[tipBtn.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor constant:0]
]];
} else {
[self addConstraint:[NSLayoutConstraint constraintWithItem:tipBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:20.0]];
}

[self addConstraints:@[
[NSLayoutConstraint constraintWithItem:tipBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0],
[NSLayoutConstraint constraintWithItem:tipBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]
]];


[tipBtn addConstraints:@[
[NSLayoutConstraint constraintWithItem:tipLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:tipBtn attribute:NSLayoutAttributeLeft multiplier:1.0 constant:8],
[NSLayoutConstraint constraintWithItem:tipLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:tipBtn attribute:NSLayoutAttributeTop multiplier:1.0 constant:0],
[NSLayoutConstraint constraintWithItem:tipLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:tipBtn attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]
]];

[tipBtn addConstraints:@[
[NSLayoutConstraint constraintWithItem:dragTipLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:tipBtn attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10],
[NSLayoutConstraint constraintWithItem:dragTipLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:tipLabel attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0],
[NSLayoutConstraint constraintWithItem:dragTipLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:tipLabel attribute:NSLayoutAttributeRight multiplier:1.0 constant:8]
]];
[dragTipLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[tipLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[dragTipLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[tipLabel setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

self.btn = tipBtn;
self.statusLable = tipLabel;

[self.btn addGestureRecognizer:self.panGestureRecognizer];
self.btn.growingHelper_onClick = self.onButtonClick;
self.growingViewLevel = 0;
}
return self;
}

- (void)layoutSubviews {
[super layoutSubviews];
self.statusLable.frame = CGRectMake(0,0,self.bounds.size.width, [[UIApplication sharedApplication] statusBarFrame].size.height);
self.btn.frame = self.statusLable.bounds;
}

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (self == view) {
Expand All @@ -77,14 +133,4 @@ - (BOOL)growingNodeIsBadNode {
return NO;
}

- (void)didTapStatusBar:(id)gesture {
if (self.onButtonClick) self.onButtonClick();
}

- (void)dealloc {
if (@available(iOS 13.0, *)) {
[[GrowingStatusBarEventManager sharedInstance] removeStatusBarObserver:self];
}
}

@end
30 changes: 0 additions & 30 deletions Modules/WebCircle/GrowingStatusBarAutotracker.h

This file was deleted.

Loading

0 comments on commit a90c42d

Please sign in to comment.