提交 4a45afd4 编写于 作者: J jackjintai

Merge remote-tracking branch 'origin/master'

......@@ -8,7 +8,12 @@
#import <UIKit/UIKit.h>
/// 入口滑动浮窗(默认记录上次坐标)
@interface DoraemonEntryView : UIWindow
/// 是否自动停靠,默认为YES
@property (nonatomic, assign) BOOL autoDock;
// 定制位置
- (instancetype)initWithStartPoint:(CGPoint)startingPosition;
- (void)show;
......
......@@ -136,6 +136,10 @@
}
- (void)pan:(UIPanGestureRecognizer *)sender{
if (self.autoDock) {
[self autoDocking:sender];
return;
}
//1、获得拖动位移
CGPoint offsetPoint = [sender translationInView:sender.view];
//2、清空拖动位移
......@@ -157,6 +161,61 @@
newY = DoraemonScreenHeight - _kEntryViewSize/2;
}
panView.center = CGPointMake(newX, newY);
[[NSUserDefaults standardUserDefaults] setObject:@{
@"x":[NSNumber numberWithFloat:newX],
@"y":[NSNumber numberWithFloat:newY]
} forKey:@"FloatViewCenterLocation"];
}
- (void)autoDocking:(UIPanGestureRecognizer *)panGestureRecognizer {
UIView *panView = panGestureRecognizer.view;
switch (panGestureRecognizer.state) {
case UIGestureRecognizerStateBegan:
case UIGestureRecognizerStateChanged:
{
CGPoint translation = [panGestureRecognizer translationInView:panView];
[panGestureRecognizer setTranslation:CGPointZero inView:panView];
panView.center = CGPointMake(panView.center.x + translation.x, panView.center.y + translation.y);
}
break;
case UIGestureRecognizerStateEnded:
case UIGestureRecognizerStateCancelled:
{
CGPoint location = panView.center;
CGFloat centerX;
CGFloat safeBottom = 0;
if (@available(iOS 11.0, *)) {
safeBottom = self.safeAreaInsets.bottom;
}
CGFloat centerY = MAX(MIN(location.y, CGRectGetMaxY([UIScreen mainScreen].bounds)-safeBottom), [UIApplication sharedApplication].statusBarFrame.size.height);
if(location.x > CGRectGetWidth([UIScreen mainScreen].bounds)/2.f)
{
centerX = CGRectGetWidth([UIScreen mainScreen].bounds)-6;
}
else
{
centerX = 6.f;
}
[[NSUserDefaults standardUserDefaults] setObject:@{
@"x":[NSNumber numberWithFloat:centerX],
@"y":[NSNumber numberWithFloat:centerY]
} forKey:@"FloatViewCenterLocation"];
[UIView animateWithDuration:0.3 animations:^{
panView.center = CGPointMake(centerX, centerY);
}];
}
default:
break;
}
}
- (void)setAutoDock:(BOOL)autoDock {
_autoDock = autoDock;
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"FloatViewCenterLocation"];
if (dict && dict[@"x"] && dict[@"y"]) {
self.center = CGPointMake([dict[@"x"] integerValue], [dict[@"y"] integerValue]);
}
}
@end
......@@ -120,6 +120,10 @@ typedef NS_ENUM(NSUInteger, DoraemonManagerPluginType) {
- (void)installWithCustomBlock:(void(^)(void))customBlock;
/// 设置是否自动停靠屏幕边缘
/// @param autoDock bool
- (void)setAutoDock:(BOOL)autoDock;
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic, copy) DoraemonH5DoorBlock h5DoorBlock;
......
......@@ -102,6 +102,7 @@ typedef void (^DoraemonPerformanceBlock)(NSDictionary *);
[self installWithCustomBlock:^{
//什么也没发生
}];
[self setAutoDock:YES];
}
- (void)installWithCustomBlock:(void(^)(void))customBlock{
......@@ -191,6 +192,9 @@ typedef void (^DoraemonPerformanceBlock)(NSDictionary *);
}
- (void)setAutoDock:(BOOL)autoDock {
self.entryView.autoDock = autoDock;
}
/**
初始化内置工具数据
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册