Browse Source

fix BarNotification for iPhoneX

Marino Faggiana 7 năm trước cách đây
mục cha
commit
ad33926cd1

+ 7 - 4
Libraries external/JDStatusBarNotification/JDStatusBarNotification.m

@@ -483,13 +483,16 @@
 {
   CGFloat width = MAX(rect.size.width, rect.size.height);
   CGFloat height = MIN(rect.size.width, rect.size.height);
-
+    
   // on ios7 fix position, if statusBar has double height
   CGFloat yPos = 0;
-  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && height > 20.0) {
-    yPos = -height/2.0;
+  if ([JDStatusBarView isIphoneX]) {
+    height = 64;
+  } else {
+    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && height > 20.0) {
+      yPos = -height/2.0;
+    }
   }
-
   _topBar.frame = CGRectMake(0, yPos, width, height);
 }
 

+ 3 - 0
Libraries external/JDStatusBarNotification/JDStatusBarView.h

@@ -12,4 +12,7 @@
 @property (nonatomic, strong, readonly) UILabel *textLabel;
 @property (nonatomic, strong, readonly) UIActivityIndicatorView *activityIndicatorView;
 @property (nonatomic, assign) CGFloat textVerticalPositionAdjustment;
+
++ (BOOL)isIphoneX;
+
 @end

+ 49 - 2
Libraries external/JDStatusBarNotification/JDStatusBarView.m

@@ -7,6 +7,9 @@
 //
 
 #import "JDStatusBarView.h"
+#import <sys/utsname.h>
+
+CGFloat const ADJUSTIPHONEX = 28;
 
 @interface JDStatusBarView ()
 @property (nonatomic, strong) UILabel *textLabel;
@@ -54,10 +57,17 @@
 - (void)layoutSubviews;
 {
   [super layoutSubviews];
+    
+  CGFloat yPos = self.textVerticalPositionAdjustment;
+  CGFloat textLabelHeight = self.bounds.size.height-1;
+  if ([JDStatusBarView isIphoneX]) {
+    yPos += ADJUSTIPHONEX;
+    textLabelHeight -= ADJUSTIPHONEX;
+  }
 
   // label
-  self.textLabel.frame = CGRectMake(0, 1+self.textVerticalPositionAdjustment,
-                                    self.bounds.size.width, self.bounds.size.height-1);
+  self.textLabel.frame = CGRectMake(0, 1+yPos,
+                                    self.bounds.size.width, textLabelHeight);
 
   // activity indicator
   if (_activityIndicatorView ) {
@@ -65,6 +75,11 @@
     CGRect indicatorFrame = _activityIndicatorView.frame;
     indicatorFrame.origin.x = round((self.bounds.size.width - textSize.width)/2.0) - indicatorFrame.size.width - 8.0;
     indicatorFrame.origin.y = ceil(1+(self.bounds.size.height - indicatorFrame.size.height)/2.0);
+      
+  if ([JDStatusBarView isIphoneX]) {
+    indicatorFrame.origin.y += ADJUSTIPHONEX * 0.5;
+  }
+      
     _activityIndicatorView.frame = indicatorFrame;
   }
 }
@@ -92,4 +107,36 @@
   return textSize;
 }
 
++ (BOOL)isIphoneX
+{
+  NSString *modelName = [self modelName];
+  return [modelName isEqualToString: @"Phone10,3"] || [modelName isEqualToString: @"iPhone10,6"] || [JDStatusBarView isSimulatorIphoneX];
+}
+
++ (NSString *)modelName
+{
+  struct utsname systemInfo;
+  uname(&systemInfo);
+  return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
+}
+
++ (BOOL)isSimulatorIphoneX
+{
+  if ([JDStatusBarView isSimulator] && [UIScreen mainScreen].bounds.size.height == 812) {
+    return YES;
+  } else {
+    return NO;
+  }
+}
+
++ (BOOL)isSimulator
+{
+#if TARGET_OS_SIMULATOR
+  return YES;
+#else
+  return NO;
+#endif
+}
+
+
 @end

+ 6 - 4
iOSClient/Main/CCMain.m

@@ -2986,8 +2986,6 @@
     backgroundColor.G = 1;
     backgroundColor.B = 1;
     
-    NSInteger originY = 60;
-
     options.arrowSize = 9;
     options.marginXSpacing = 7;
     options.marginYSpacing = 10;
@@ -3001,8 +2999,12 @@
     options.menuBackgroundColor = backgroundColor;
     
     CGRect rect = self.view.frame;
-    rect.origin.y = rect.origin.y + originY;
-    rect.size.height = rect.size.height - originY;
+    CGFloat safeAreaTop = 0;
+    if (@available(iOS 11, *)) {
+        safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
+    }
+    rect.origin.y = rect.origin.y + 50 + safeAreaTop;
+    rect.size.height = rect.size.height + 50 + safeAreaTop;
     
     [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
     [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];