BDFaceCalculateTool.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. + (CGFloat)screenWidth {
  56. return [UIScreen mainScreen].bounds.size.width;
  57. }
  58. + (CGFloat)screenHeight {
  59. return [UIScreen mainScreen].bounds.size.height;
  60. }
  61. + (BOOL)noNullDic:(NSDictionary *)dic {
  62. if (dic
  63. && [dic isKindOfClass:[NSDictionary class]]
  64. && dic.allKeys.count > 0) {
  65. return YES;
  66. }
  67. return NO;
  68. }
  69. @end