未验证 提交 f4da3a2b 编写于 作者: Y yixiangboy 提交者: GitHub

Merge pull request #150 from HuginChen/master

解决 issues105 横屏APP还是有问题
......@@ -28,7 +28,7 @@
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.windowLevel = UIWindowLevelStatusBar + 100.f;
self.windowLevel = UIWindowLevelStatusBar + 1.f;
self.backgroundColor = [UIColor doraemon_colorWithHex:0x000000 andAlpha:0.33];
[self addRootVc];
......
......@@ -29,7 +29,7 @@
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.windowLevel = UIWindowLevelStatusBar + 100.f;
self.windowLevel = UIWindowLevelStatusBar + 1.f;
self.backgroundColor = [UIColor doraemon_colorWithString:@"#427dbe"];
_contentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
......
......@@ -10,7 +10,10 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoraemonVisualInfoWindow : UIWindow
/** 显示的文本 */
@property (nonatomic, copy) NSString *infoText;
/** 显示的属性文本 */
@property (nonatomic, copy) NSAttributedString *infoAttributedText;
@end
NS_ASSUME_NONNULL_END
......@@ -8,8 +8,78 @@
#import "DoraemonVisualInfoWindow.h"
#import "DoraemonDefine.h"
@interface DoraemonVisualInfoViewController : UIViewController
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) UILabel *infoLabel;
@end
@implementation DoraemonVisualInfoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUI];
}
- (void)initUI {
// 视图加载完成之前拿不到当前window,所以这里等待 UI 线程执行完成
dispatch_async(dispatch_get_main_queue(), ^{
CGSize viewSize = self.view.window.bounds.size;
CGFloat closeWidth = kDoraemonSizeFrom750(44);
CGFloat closeHeight = kDoraemonSizeFrom750(44);
_closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(viewSize.width - closeWidth - kDoraemonSizeFrom750(16), kDoraemonSizeFrom750(16), closeWidth, closeHeight)];
[_closeBtn setBackgroundImage:[UIImage doraemon_imageNamed:@"doraemon_close"] forState:UIControlStateNormal];
[_closeBtn addTarget:self action:@selector(closeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_closeBtn];
_infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750(32), 0, viewSize.width - kDoraemonSizeFrom750(32 + 16) - closeWidth , viewSize.height)];
_infoLabel.backgroundColor =[UIColor clearColor];
_infoLabel.textColor = [UIColor doraemon_black_1];
_infoLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750(24)];
_infoLabel.numberOfLines = 0;
[self.view addSubview:_infoLabel];
[(id)self.view.window setInfoLabel:_infoLabel];
});
}
#pragma mark - Actions
- (void)closeBtnClicked:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:DoraemonClosePluginNotification object:nil userInfo:nil];
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
dispatch_async(dispatch_get_main_queue(), ^{
if (size.height < size.width) {
self.view.window.frame = CGRectMake(49, 20, size.height, size.width);
} else {
self.view.window.frame = CGRectMake(kDoraemonSizeFrom750(30), DoraemonScreenHeight - _infoLabel.frame.size.height - kDoraemonSizeFrom750(30), size.height, size.width);
}
});
}
@end
@interface DoraemonVisualInfoWindow ()
@property (nonatomic, weak) UILabel *infoLabel;
@end
@implementation DoraemonVisualInfoWindow
#pragma mark - set
- (void)setInfoText:(NSString *)infoText {
_infoText = infoText;
_infoLabel.text = infoText;
}
- (void)setInfoAttributedText:(NSAttributedString *)infoAttributedText {
_infoAttributedText = infoAttributedText;
_infoLabel.attributedText = infoAttributedText;
}
#pragma mark - Lifecycle
- (instancetype)initWithFrame:(CGRect)frame {
......@@ -26,6 +96,8 @@
self.layer.borderWidth = 1.;
self.layer.borderColor = [UIColor doraemon_colorWithHex:0x999999 andAlpha:0.2].CGColor;
self.windowLevel = UIWindowLevelAlert;
[[DoraemonVisualInfoViewController alloc] init];
self.rootViewController = [[DoraemonVisualInfoViewController alloc] init];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self addGestureRecognizer:pan];
......
......@@ -25,7 +25,7 @@
self.layer.delegate = self;
self.layer.borderWidth = 1;
self.layer.borderColor = [[UIColor clearColor] CGColor];
self.windowLevel = UIWindowLevelStatusBar + 1;
self.windowLevel = UIWindowLevelStatusBar + 1.f;
self.layer.contentsScale = [[UIScreen mainScreen] scale];
}
return self;
......
......@@ -20,7 +20,10 @@
#define DoraemonScreenHeight [UIScreen mainScreen].bounds.size.height
//根据750*1334分辨率计算size
#define kDoraemonSizeFrom750(x) ((x)*DoraemonScreenWidth/750)
#define kDoraemonSizeFrom750(x) ((x)*DoraemonScreenWidth/750)
// 如果横屏显示
#define kDoraemonSizeFrom750_Landscape(x) UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ? ((x)*DoraemonScreenHeight/750) : kDoraemonSizeFrom750(x)
#define IS_IPHONE_X_Series [DoraemonAppInfoUtil isIPhoneXSeries]
#define IPHONE_NAVIGATIONBAR_HEIGHT (IS_IPHONE_X_Series ? 88 : 64)
......
......@@ -31,7 +31,7 @@
self.backgroundColor = [UIColor clearColor];
self.windowLevel = UIWindowLevelStatusBar + 100.f;
self.windowLevel = UIWindowLevelStatusBar + 1.f;
NSString *version= [UIDevice currentDevice].systemVersion;
if(version.doubleValue >=10.0) {
if (!self.rootViewController) {
......
......@@ -24,7 +24,7 @@
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.windowLevel = UIWindowLevelStatusBar + 50.f;
self.windowLevel = UIWindowLevelStatusBar + 1.f;
self.backgroundColor = [UIColor clearColor];
self.hidden = YES;
}
......
......@@ -87,9 +87,7 @@
CGPoint centerPoint = CGPointMake(newX, newY);
panView.center = centerPoint;
}
#pragma mark - Delegate
#pragma mark DoraemonColorPickInfoViewDelegate
- (void)closeBtnClicked:(id)sender onColorPickInfoView:(DoraemonColorPickInfoView *)colorPickInfoView {
......
......@@ -47,7 +47,7 @@ static CGFloat const kColorPickWindowSize = 150;
self = [super initWithFrame:CGRectMake(DoraemonScreenWidth/2-kColorPickWindowSize/2, DoraemonScreenHeight/2-kColorPickWindowSize/2, kColorPickWindowSize, kColorPickWindowSize)];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.windowLevel = UIWindowLevelStatusBar + 11.f;
self.windowLevel = UIWindowLevelStatusBar + 1.f;
if (!self.rootViewController) {
self.rootViewController = [[UIViewController alloc] init];
}
......
......@@ -20,9 +20,7 @@ static CGFloat const kViewCheckSize = 62;
@property (nonatomic, strong) UILabel *topLabel;
@property (nonatomic, strong) UILabel *rightLabel;
@property (nonatomic, strong) UILabel *bottomLabel;
@property (nonatomic, strong) DoraemonVisualInfoWindow *infoWindow;
@property (nonatomic, strong) UILabel *infoLbl;
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) DoraemonVisualInfoWindow *infoWindow;
@end
......@@ -90,19 +88,7 @@ static CGFloat const kViewCheckSize = 62;
_infoWindow = [[DoraemonVisualInfoWindow alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750(30), DoraemonScreenHeight - kDoraemonSizeFrom750(100) - kDoraemonSizeFrom750(30), DoraemonScreenWidth - 2*kDoraemonSizeFrom750(30), kDoraemonSizeFrom750(100))];
CGFloat closeWidth = kDoraemonSizeFrom750(44);
CGFloat closeHeight = kDoraemonSizeFrom750(44);
_closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(_infoWindow.bounds.size.width - closeWidth - kDoraemonSizeFrom750(32), (_infoWindow.bounds.size.height - closeHeight) / 2.0, closeWidth, closeHeight)];
[_closeBtn setBackgroundImage:[UIImage doraemon_imageNamed:@"doraemon_close"] forState:UIControlStateNormal];
[_closeBtn addTarget:self action:@selector(closeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[_infoWindow addSubview:_closeBtn];
_infoLbl = [[UILabel alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750(32), 0, _infoWindow.bounds.size.width - 2*kDoraemonSizeFrom750(32) - _closeBtn.doraemon_width , _infoWindow.bounds.size.height)];
_infoLbl.backgroundColor =[UIColor clearColor];
_infoLbl.textColor = [UIColor doraemon_black_1];
_infoLbl.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750(24)];
[self configInfoLblText];
[_infoWindow addSubview:_infoLbl];
[self configInfoLblText];
}
return self;
}
......@@ -150,13 +136,9 @@ static CGFloat const kViewCheckSize = 62;
}
- (void)configInfoLblText {
_infoLbl.text = [NSString stringWithFormat:@"位置:左%@ 右%@ 上%@ 下%@", _leftLabel.text, _rightLabel.text, _topLabel.text, _bottomLabel.text];
}
- (void)closeBtnClicked:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:DoraemonClosePluginNotification object:nil userInfo:nil];
_infoWindow.infoText = [NSString stringWithFormat:@"位置:左%@ 右%@ 上%@ 下%@", _leftLabel.text, _rightLabel.text, _topLabel.text, _bottomLabel.text];
}
- (void)show {
_infoWindow.hidden = NO;
......
......@@ -15,9 +15,7 @@ static CGFloat const kViewCheckSize = 62;
@interface DoraemonViewCheckView()
@property (nonatomic, strong) UIView *viewBound;//当前需要探测的view的边框
@property (nonatomic, strong) DoraemonVisualInfoWindow *viewInfoWindow;//顶部被探测到的view的信息显示的UIwindow
@property (nonatomic, strong) UILabel *viewInfoLabel;//顶部被探测到的view的信息显示
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) DoraemonVisualInfoWindow *infoWindow;//顶部被探测到的view的信息显示的UIwindow
@property (nonatomic, assign) CGFloat left;
@property (nonatomic, assign) CGFloat top;
......@@ -46,32 +44,12 @@ static CGFloat const kViewCheckSize = 62;
_viewBound.layer.borderColor = [UIColor doraemon_colorWithHex:0xCC3A4B].CGColor;
_viewBound.layer.zPosition = FLT_MAX;
_viewInfoWindow = [[DoraemonVisualInfoWindow alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750(30), DoraemonScreenHeight - kDoraemonSizeFrom750(180) - kDoraemonSizeFrom750(30), DoraemonScreenWidth - 2*kDoraemonSizeFrom750(30), kDoraemonSizeFrom750(180))];
[_viewInfoWindow makeKeyAndVisible];
_viewInfoWindow.hidden = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.window makeKeyAndVisible];//将keyWindow还是交给原来那个
});
CGFloat closeWidth = kDoraemonSizeFrom750(44);
CGFloat closeHeight = kDoraemonSizeFrom750(44);
_closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(_viewInfoWindow.bounds.size.width - closeWidth - kDoraemonSizeFrom750(32), kDoraemonSizeFrom750(18), closeWidth, closeHeight)];
[_closeBtn setBackgroundImage:[UIImage doraemon_imageNamed:@"doraemon_close"] forState:UIControlStateNormal];
[_closeBtn addTarget:self action:@selector(closeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[_viewInfoWindow addSubview:_closeBtn];
_viewInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750(32), kDoraemonSizeFrom750(30), _viewInfoWindow.bounds.size.width - 2*kDoraemonSizeFrom750(32) - _closeBtn.doraemon_width , _viewInfoWindow.bounds.size.height - 2*kDoraemonSizeFrom750(30))];
_viewInfoLabel.numberOfLines = 0;
_viewInfoLabel.backgroundColor =[UIColor clearColor];
_viewInfoLabel.textColor = [UIColor doraemon_black_1];
_viewInfoLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750(24)];
[_viewInfoWindow addSubview:_viewInfoLabel];
_infoWindow = [[DoraemonVisualInfoWindow alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750(30), DoraemonScreenHeight - kDoraemonSizeFrom750(180) - kDoraemonSizeFrom750(30), DoraemonScreenWidth - 2*kDoraemonSizeFrom750(30), kDoraemonSizeFrom750(180))];
}
return self;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
_left = point.x;
......@@ -82,8 +60,8 @@ static CGFloat const kViewCheckSize = 62;
_viewBound.frame = frame;
[self.window addSubview:_viewBound];
// _viewInfoWindow.hidden = NO;
_viewInfoLabel.attributedText = [self viewInfo:view];
// _infoWindow.hidden = NO;
_infoWindow.infoAttributedText = [self viewInfo:view];
}
......@@ -96,36 +74,32 @@ static CGFloat const kViewCheckSize = 62;
UIView *view = [self topView:self.window Point:topPoint];
CGRect frame = [self.window convertRect:view.bounds fromView:view];
_viewBound.frame = frame;
// _viewInfoWindow.hidden = NO;
_viewInfoLabel.attributedText = [self viewInfo:view];
// _infoWindow.hidden = NO;
_infoWindow.infoAttributedText = [self viewInfo:view];
}
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[_viewBound removeFromSuperview];
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [UIView animateWithDuration:0.5 animations:^{
// _viewInfoWindow.alpha = 0;
// } completion:^(BOOL finished) {
// _viewInfoWindow.hidden = YES;
// _viewInfoWindow.alpha = 1;
// }];
// });
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [UIView animateWithDuration:0.5 animations:^{
// _viewInfoWindow.alpha = 0;
// } completion:^(BOOL finished) {
// _viewInfoWindow.hidden = YES;
// _viewInfoWindow.alpha = 1;
// }];
// });
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[_viewBound removeFromSuperview];
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [UIView animateWithDuration:0.5 animations:^{
// _viewInfoWindow.alpha = 0;
// } completion:^(BOOL finished) {
// _viewInfoWindow.hidden = YES;
// _viewInfoWindow.alpha = 1;
// }];
// });
}
- (void)closeBtnClicked:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:DoraemonClosePluginNotification object:nil userInfo:nil];
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [UIView animateWithDuration:0.5 animations:^{
// _viewInfoWindow.alpha = 0;
// } completion:^(BOOL finished) {
// _viewInfoWindow.hidden = YES;
// _viewInfoWindow.alpha = 1;
// }];
// });
}
-(UIView*)topView:(UIView*)view Point:(CGPoint) point{
......@@ -155,13 +129,13 @@ static CGFloat const kViewCheckSize = 62;
}
- (void)show {
_viewInfoWindow.hidden = NO;
_infoWindow.hidden = NO;
self.hidden = NO;
}
- (void)hide {
[_viewBound removeFromSuperview];
_viewInfoWindow.hidden = YES;
_infoWindow.hidden = YES;
self.hidden = YES;
}
......@@ -186,13 +160,15 @@ static CGFloat const kViewCheckSize = 62;
NSString *string = [NSString stringWithFormat:showString];
// 行间距
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
style.lineSpacing = kDoraemonSizeFrom750(12);
style.lineSpacing = kDoraemonSizeFrom750_Landscape(12);
style.lineBreakMode = NSLineBreakByTruncatingTail;
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string];
[attrString addAttributes:@{
NSParagraphStyleAttributeName : style,
NSFontAttributeName : [UIFont systemFontOfSize:kDoraemonSizeFrom750(24)],
NSFontAttributeName : [UIFont systemFontOfSize: kDoraemonSizeFrom750_Landscape(24)],
NSForegroundColorAttributeName : [UIColor doraemon_black_1]
}
range:NSMakeRange(0, string.length)];
......@@ -228,7 +204,7 @@ static CGFloat const kViewCheckSize = 62;
if (alpha < 255) {//存在透明度
hex = [NSString stringWithFormat:@"%@ alpha:%.2f",hex,(CGColorGetComponents(color.CGColor))[3]];
}
return hex;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册