react-native-navigation的迁移库

RNNViewLocation.m 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #import "RNNViewLocation.h"
  2. #import "RNNReactView.h"
  3. #import <React/RCTSafeAreaView.h>
  4. @implementation RNNViewLocation
  5. - (instancetype)initWithFromElement:(UIView *)fromElement toElement:(UIView *)toElement {
  6. self = [super init];
  7. self.fromFrame = [self convertViewFrame:fromElement];
  8. self.toFrame = [self convertViewFrame:toElement];
  9. self.fromAngle = [self getViewAngle:fromElement];
  10. self.toAngle = [self getViewAngle:toElement];
  11. return self;
  12. }
  13. - (CGRect)convertViewFrame:(UIView *)view {
  14. UIView* topMostView = [self topMostView:view];
  15. CGPoint center = [view.superview convertPoint:view.center toView:nil];
  16. CGFloat safeAreaTopOffset = [self safeAreaOffsetForView:view inView:topMostView];
  17. center.y += safeAreaTopOffset;
  18. CGRect frame = CGRectMake(center.x - view.bounds.size.width / 2, center.y - view.bounds.size.height / 2, view.bounds.size.width, view.bounds.size.height);
  19. return frame;
  20. }
  21. - (CGFloat)getViewAngle:(UIView *)view {
  22. CGFloat radians = atan2f(view.transform.b, view.transform.a);
  23. return radians;
  24. }
  25. - (UIView *)topMostView:(UIView *)view {
  26. if ([view isKindOfClass:[RNNReactView class]]) {
  27. return view;
  28. } else {
  29. return [self topMostView:view.superview];
  30. }
  31. }
  32. - (CGFloat)safeAreaOffsetForView:(UIView *)view inView:(UIView *)inView {
  33. CGFloat safeAreaOffset = inView.layoutMarginsGuide.layoutFrame.origin.y;
  34. if ([view isKindOfClass:RCTSafeAreaView.class] && [[view valueForKey:@"_currentSafeAreaInsets"] UIEdgeInsetsValue].top != safeAreaOffset) {
  35. return safeAreaOffset;
  36. } else if (view.superview) {
  37. return [self safeAreaOffsetForView:view.superview inView:inView];
  38. }
  39. return 0;
  40. }
  41. @end