引言

本文以​​pod 'PGDatePicker' ,'2.6.9'·​​为例子

I、iOS视图置顶方案

让一个View至于最顶端, 避免被其他子视图遮盖住


zPosition : 同级Layer改变显示顺序

bringSubviewToFront: 让指定子视图显示到窗口最前面



昵称:#公众号:iOS逆向


II、案例:适配iOS12系统上日期视图被筛选视图遮挡问题

适配iOS12系统上日期视图被筛选视图遮挡问题

背景:为了适配iOS12系统上日期视图被筛选视图遮挡问题


iOS修改第三方库日期视图的层级来避免被其他视图遮挡(针对PGDatePicker进行iOS12的适配)_iOS


方案:修改第三方库日期视图的层级


修改PGDatePickManager,在viewWillLayoutSubviews将contentView和dismissView添加到keyWindow

由于是第三方SDK,可使用自定义类重写viewWillLayoutSubviews,但是推荐在分类使用方法交换进行实现


2.1 自定义类重写viewWillLayoutSubviews

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];

self.headerView.style = self.style;
self.dismissView.frame = self.view.bounds;
self.contentView.backgroundColor = self.datePicker.backgroundColor;
if (self.style == PGDatePickManagerStyleSheet) {
[self setupStyleSheet];
}else if (self.style == PGDatePickManagerStyleAlertTopButton) {
[self setupStyleAlert];
}else {
[self setupStyle3];
}
// [self.view bringSubviewToFront:self.contentView];
[[UIApplication sharedApplication].keyWindow addSubview:_dismissView];
[[UIApplication sharedApplication].keyWindow addSubview:self.contentView];

}

2.2 在分类使用方法交换让日期视图视图置顶

.h

//PGDatePickManager+ios12.h
#import "PGDatePickManager.h"

NS_ASSUME_NONNULL_BEGIN

@interface PGDatePickManager (ios12)

@end

NS_ASSUME_NONNULL_END

.m

#import "PGDatePickManager+ios12.h"



@implementation PGDatePickManager (ios12)

+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

NSArray *selStringsArray = @[@"viewWillLayoutSubviews"];


[selStringsArray enumerateObjectsUsingBlock:^(NSString *selString, NSUInteger idx, BOOL *stop) {
NSString *mySelString = [@"sd_" stringByAppendingString:selString];

Method originalMethod = class_getInstanceMethod(self, NSSelectorFromString(selString));
Method myMethod = class_getInstanceMethod(self, NSSelectorFromString(mySelString));
method_exchangeImplementations(originalMethod, myMethod);
}];
});
}
- (void)sd_viewWillLayoutSubviews{

[self sd_viewWillLayoutSubviews];

[UIApplication.sharedApplication.delegate.window bringSubviewToFront:self.view.superview];

}





@end

see also

公众号:iOS逆向