Commit c4f53fa8 authored by yuzheng's avatar yuzheng

适配iPhone12,使用safeAreaInsets升级iPhoneX系列手机适配方式

parent 74da94c1
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
_previewView.frame = self.view.bounds; _previewView.frame = self.view.bounds;
_previewView.scrollView.frame = self.view.bounds; _previewView.scrollView.frame = self.view.bounds;
CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 44 + (83 - 49) : 44; CGFloat toolBarHeight = 44 + [TZCommonTools tz_safeAreaInsets].bottom;
_toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight); _toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight);
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44); _doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
......
...@@ -305,6 +305,7 @@ ...@@ -305,6 +305,7 @@
@interface TZCommonTools : NSObject @interface TZCommonTools : NSObject
+ (UIEdgeInsets)tz_safeAreaInsets;
+ (BOOL)tz_isIPhoneX; + (BOOL)tz_isIPhoneX;
+ (CGFloat)tz_statusBarHeight; + (CGFloat)tz_statusBarHeight;
// 获得Info.plist数据字典 // 获得Info.plist数据字典
......
...@@ -905,15 +905,40 @@ ...@@ -905,15 +905,40 @@
@implementation TZCommonTools @implementation TZCommonTools
+ (UIEdgeInsets)tz_safeAreaInsets {
UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
if (![window isKeyWindow]) {
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
if (CGRectEqualToRect(keyWindow.bounds, [UIScreen mainScreen].bounds)) {
window = keyWindow;
}
}
if (@available(iOS 11.0, *)) {
UIEdgeInsets insets = [window safeAreaInsets];
return insets;
}
return UIEdgeInsetsZero;
}
+ (BOOL)tz_isIPhoneX { + (BOOL)tz_isIPhoneX {
if ([UIWindow instancesRespondToSelector:@selector(safeAreaInsets)]) {
return [self tz_safeAreaInsets].bottom > 0;
}
return (CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(375, 812)) || return (CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(375, 812)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(812, 375)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(812, 375)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(414, 896)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(414, 896)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(896, 414))); CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(896, 414)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(390, 844)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(844, 390)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(428, 926)) ||
CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(926, 428)));
} }
+ (CGFloat)tz_statusBarHeight { + (CGFloat)tz_statusBarHeight {
return [self tz_isIPhoneX] ? 44 : 20; if ([UIWindow instancesRespondToSelector:@selector(safeAreaInsets)]) {
return [self tz_safeAreaInsets].top;
}
return 20;
} }
// 获得Info.plist数据字典 // 获得Info.plist数据字典
......
...@@ -349,7 +349,7 @@ static CGFloat itemMargin = 5; ...@@ -349,7 +349,7 @@ static CGFloat itemMargin = 5;
CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height; CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height;
BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden; BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden;
BOOL isFullScreen = self.view.tz_height == [UIScreen mainScreen].bounds.size.height; BOOL isFullScreen = self.view.tz_height == [UIScreen mainScreen].bounds.size.height;
CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 50 + (83 - 49) : 50; CGFloat toolBarHeight = 50 + [TZCommonTools tz_safeAreaInsets].bottom;
if (self.navigationController.navigationBar.isTranslucent) { if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight; top = naviBarHeight;
if (!isStatusBarHidden && isFullScreen) top += [TZCommonTools tz_statusBarHeight]; if (!isStatusBarHidden && isFullScreen) top += [TZCommonTools tz_statusBarHeight];
......
...@@ -342,8 +342,8 @@ ...@@ -342,8 +342,8 @@
CGFloat progressY = (self.tz_height - progressWH) / 2; CGFloat progressY = (self.tz_height - progressWH) / 2;
_progressView.frame = CGRectMake(progressX, progressY, progressWH, progressWH); _progressView.frame = CGRectMake(progressX, progressY, progressWH, progressWH);
[self recoverSubviews]; [self recoverSubviews];
_iCloudErrorIcon.frame = CGRectMake(20, [TZCommonTools tz_isIPhoneX] ? 88 + 10 : 64 + 10, 28, 28); _iCloudErrorIcon.frame = CGRectMake(20, [TZCommonTools tz_statusBarHeight] + 44 + 10, 28, 28);
_iCloudErrorLabel.frame = CGRectMake(53, [TZCommonTools tz_isIPhoneX] ? 88 + 10 : 64 + 10, self.tz_width - 63, 28); _iCloudErrorLabel.frame = CGRectMake(53, [TZCommonTools tz_statusBarHeight] + 44 + 10, self.tz_width - 63, 28);
} }
#pragma mark - UITapGestureRecognizer Event #pragma mark - UITapGestureRecognizer Event
...@@ -484,8 +484,8 @@ ...@@ -484,8 +484,8 @@
[super layoutSubviews]; [super layoutSubviews];
_playerLayer.frame = self.bounds; _playerLayer.frame = self.bounds;
_playButton.frame = CGRectMake(0, 64, self.tz_width, self.tz_height - 64 - 44); _playButton.frame = CGRectMake(0, 64, self.tz_width, self.tz_height - 64 - 44);
_iCloudErrorIcon.frame = CGRectMake(20, [TZCommonTools tz_isIPhoneX] ? 88 + 10 : 64 + 10, 28, 28); _iCloudErrorIcon.frame = CGRectMake(20, [TZCommonTools tz_statusBarHeight] + 44 + 10, 28, 28);
_iCloudErrorLabel.frame = CGRectMake(53, [TZCommonTools tz_isIPhoneX] ? 88 + 10 : 64 + 10, self.tz_width - 63, 28); _iCloudErrorLabel.frame = CGRectMake(53, [TZCommonTools tz_statusBarHeight] + 44 + 10, self.tz_width - 63, 28);
} }
- (void)photoPreviewCollectionViewDidScroll { - (void)photoPreviewCollectionViewDidScroll {
......
...@@ -275,7 +275,7 @@ ...@@ -275,7 +275,7 @@
[_collectionView reloadData]; [_collectionView reloadData];
} }
CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 44 + (83 - 49) : 44; CGFloat toolBarHeight = 44 + [TZCommonTools tz_safeAreaInsets].bottom;
CGFloat toolBarTop = self.view.tz_height - toolBarHeight; CGFloat toolBarTop = self.view.tz_height - toolBarHeight;
_toolBar.frame = CGRectMake(0, toolBarTop, self.view.tz_width, toolBarHeight); _toolBar.frame = CGRectMake(0, toolBarTop, self.view.tz_width, toolBarHeight);
if (_tzImagePickerVc.allowPickingOriginalPhoto) { if (_tzImagePickerVc.allowPickingOriginalPhoto) {
......
...@@ -153,7 +153,7 @@ ...@@ -153,7 +153,7 @@
CGFloat statusBarHeight = isFullScreen ? [TZCommonTools tz_statusBarHeight] : 0; CGFloat statusBarHeight = isFullScreen ? [TZCommonTools tz_statusBarHeight] : 0;
CGFloat statusBarAndNaviBarHeight = statusBarHeight + self.navigationController.navigationBar.tz_height; CGFloat statusBarAndNaviBarHeight = statusBarHeight + self.navigationController.navigationBar.tz_height;
_playerLayer.frame = self.view.bounds; _playerLayer.frame = self.view.bounds;
CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 44 + (83 - 49) : 44; CGFloat toolBarHeight = 44 + [TZCommonTools tz_safeAreaInsets].bottom;
_toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight); _toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight);
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44); _doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_playButton.frame = CGRectMake(0, statusBarAndNaviBarHeight, self.view.tz_width, self.view.tz_height - statusBarAndNaviBarHeight - toolBarHeight); _playButton.frame = CGRectMake(0, statusBarAndNaviBarHeight, self.view.tz_width, self.view.tz_height - statusBarAndNaviBarHeight - toolBarHeight);
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
#pragma mark - lazy #pragma mark - lazy
- (UIView *)iCloudErrorView{ - (UIView *)iCloudErrorView{
if (!_iCloudErrorView) { if (!_iCloudErrorView) {
_iCloudErrorView = [[UIView alloc] initWithFrame:CGRectMake(0, [TZCommonTools tz_isIPhoneX] ? 88 + 10 : 64 + 10, self.view.tz_width, 28)]; _iCloudErrorView = [[UIView alloc] initWithFrame:CGRectMake(0, [TZCommonTools tz_statusBarHeight] + 44 + 10, self.view.tz_width, 28)];
UIImageView *icloud = [[UIImageView alloc] init]; UIImageView *icloud = [[UIImageView alloc] init];
icloud.image = [UIImage tz_imageNamedFromMyBundle:@"iCloudError"]; icloud.image = [UIImage tz_imageNamedFromMyBundle:@"iCloudError"];
icloud.frame = CGRectMake(20, 0, 28, 28); icloud.frame = CGRectMake(20, 0, 28, 28);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment