BDFaceCalculateTool.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // BDFaceCalculateTool.m
  3. // FaceSDKSample_IOS
  4. //
  5. // Created by Zhang,Jian(MBD) on 2020/12/2.
  6. // Copyright © 2020 Baidu. All rights reserved.
  7. //
  8. #import "BDFaceCalculateTool.h"
  9. @implementation BDFaceCalculateTool
  10. + (UIEdgeInsets)safeMargin {
  11. // 只算一次,把各个状态的值记录下来
  12. if (@available(iOS 11.0, *)) {
  13. UIEdgeInsets (^getEdge)(void) = ^(){
  14. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  15. if (!window) window = [UIWindow new];
  16. return window.safeAreaInsets;
  17. };
  18. if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
  19. static UIEdgeInsets _portraitEdge;
  20. static dispatch_once_t _portraitOnceToken;
  21. dispatch_once(&_portraitOnceToken, ^{
  22. _portraitEdge = getEdge();
  23. });
  24. return _portraitEdge;
  25. }
  26. else if ([UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationPortraitUpsideDown) {
  27. static UIEdgeInsets _portraitUpsideDownEdge;
  28. static dispatch_once_t _portraitUpsideDownOnceToken;
  29. dispatch_once(&_portraitUpsideDownOnceToken, ^{
  30. _portraitUpsideDownEdge = getEdge();
  31. });
  32. return _portraitUpsideDownEdge;
  33. }
  34. else if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
  35. static UIEdgeInsets _landscapeEdge;
  36. static dispatch_once_t _landscapeOnceToken;
  37. dispatch_once(&_landscapeOnceToken, ^{
  38. _landscapeEdge = getEdge();
  39. });
  40. return _landscapeEdge;
  41. }
  42. else {
  43. return getEdge();
  44. }
  45. } else {
  46. return UIEdgeInsetsZero;
  47. }
  48. }
  49. + (CGFloat)safeTopMargin {
  50. return [self safeMargin].top;
  51. }
  52. + (CGFloat)safeBottomMargin {
  53. return [self safeMargin].bottom;
  54. }
  55. + (BOOL)noNullDic:(NSDictionary *)dic {
  56. if (dic
  57. && [dic isKindOfClass:[NSDictionary class]]
  58. && dic.allKeys.count > 0) {
  59. return YES;
  60. }
  61. return NO;
  62. }
  63. @end