CoolOrientation.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // CoolOrientation.m
  3. // flutter_ijkplayer
  4. //
  5. // Created by Caijinglong on 2019/3/29.
  6. //
  7. #import "CoolOrientation.h"
  8. const char* const kOrientationUpdateNotificationName = "io.flutter.plugin.platform.SystemChromeOrientationNotificationName";
  9. const char* const kOrientationUpdateNotificationKey = "io.flutter.plugin.platform.SystemChromeOrientationNotificationKey";
  10. @implementation CoolOrientation
  11. - (void)setSystemChromePreferredOrientations:(NSArray*)orientations {
  12. UIInterfaceOrientationMask mask = 0;
  13. if (orientations.count == 0) {
  14. mask |= UIInterfaceOrientationMaskAll;
  15. } else {
  16. for (NSString* orientation in orientations) {
  17. if ([orientation isEqualToString:@"DeviceOrientation.portraitUp"])
  18. mask |= UIInterfaceOrientationMaskPortrait;
  19. else if ([orientation isEqualToString:@"DeviceOrientation.portraitDown"])
  20. mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
  21. else if ([orientation isEqualToString:@"DeviceOrientation.landscapeLeft"])
  22. mask |= UIInterfaceOrientationMaskLandscapeLeft;
  23. else if ([orientation isEqualToString:@"DeviceOrientation.landscapeRight"])
  24. mask |= UIInterfaceOrientationMaskLandscapeRight;
  25. }
  26. }
  27. if (!mask)
  28. return;
  29. [[NSNotificationCenter defaultCenter] postNotificationName:@(kOrientationUpdateNotificationName)
  30. object:nil
  31. userInfo:@{@(kOrientationUpdateNotificationKey)
  32. :@(mask)}];
  33. }
  34. @end