react-native-navigation的迁移库

UIViewController+Rotation.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // UIViewController+Rotation.m
  3. // ReactNativeNavigation
  4. //
  5. // Created by Ran Greenberg on 05/03/2017.
  6. // Copyright © 2017 artal. All rights reserved.
  7. //
  8. #import "UIViewController+Rotation.h"
  9. #import <objc/runtime.h>
  10. static NSString *const ORIENTATION = @"orientation";
  11. static NSString *const ORIENTATION_PORTRAIT = @"portrait";
  12. static NSString *const ORIENTATION_LANDSCAPE = @"landscape";
  13. static NSString *const ORIENTATION_AUTO = @"auto"; // defualt
  14. @interface UIViewController (Rotation)
  15. @property (nonatomic, strong) NSString *orientation;
  16. @end
  17. @implementation UIViewController (Rotation)
  18. -(NSString*)orientation {
  19. return objc_getAssociatedObject(self, @selector(orientation));
  20. }
  21. -(void)setOrientation:(NSString*)newOrientation {
  22. objc_setAssociatedObject(self, @selector(orientation), newOrientation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  23. }
  24. #pragma mark - Public API
  25. -(void)setRotation:(NSDictionary*)props {
  26. NSString *orientation = props[@"style"][ORIENTATION];
  27. if (!orientation) {
  28. orientation = props[@"appStyle"][ORIENTATION];
  29. }
  30. if (orientation) {
  31. self.orientation = orientation;
  32. }
  33. }
  34. -(UIInterfaceOrientationMask)supportedControllerOrientations {
  35. if ([self.orientation isEqualToString:ORIENTATION_PORTRAIT]) {
  36. return UIInterfaceOrientationMaskPortrait;
  37. }
  38. else if ([self.orientation isEqualToString:ORIENTATION_LANDSCAPE]) {
  39. return UIInterfaceOrientationMaskLandscape;
  40. }
  41. return UIInterfaceOrientationMaskAll;
  42. }
  43. @end