react-native-navigation的迁移库

RNNViewLocation.m 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #import "RNNViewLocation.h"
  2. @implementation RNNViewLocation
  3. - (instancetype)initWithFromElement:(RNNElementView *)fromElement toElement:(RNNElementView *)toElement startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint andVC:(UIViewController *)vc {
  4. self = [super init];
  5. self.fromFrame = [self frameFromSuperViewController:[fromElement subviews][0] andVC:vc];
  6. CGSize fromSize = self.fromFrame.size;
  7. CGPoint fromCenter = [self centerFromSuperViewController:[fromElement subviews][0] andVC:vc];
  8. fromCenter.x = fromCenter.x + startPoint.x;
  9. fromCenter.y = fromCenter.y + startPoint.y;
  10. self.fromCenter = fromCenter;
  11. CGRect toFrame = [self frameFromSuperViewController:[fromElement subviews][0] andVC:vc];
  12. CGSize toSize = self.fromFrame.size;
  13. CGPoint toCenter = [self centerFromSuperViewController:[fromElement subviews][0] andVC:vc];
  14. if (toElement) {
  15. toFrame = [self frameFromSuperViewController:[toElement subviews][0] andVC:vc];
  16. toSize = toFrame.size;
  17. toCenter = [self centerFromSuperViewController:[toElement subviews][0] andVC:vc];
  18. }
  19. toCenter.x = toCenter.x + endPoint.x;
  20. toCenter.y = toCenter.y + endPoint.y;
  21. CGAffineTransform transform = CGAffineTransformMakeScale(toSize.width/fromSize.width ,toSize.height/fromSize.height);
  22. CGAffineTransform transformBack = CGAffineTransformMakeScale(fromSize.width/toSize.width ,fromSize.height/toSize.height);
  23. self.toFrame = toFrame;
  24. self.fromSize = fromSize;
  25. self.toSize = toSize;
  26. self.toCenter = toCenter;
  27. self.transform = transform;
  28. self.transformBack = transformBack;
  29. return self;
  30. }
  31. - (CGRect)frameFromSuperViewController:(UIView *)view andVC:(UIViewController *)vc{
  32. CGPoint sharedViewFrameOrigin = [view.superview convertPoint:view.frame.origin toView:vc.view];
  33. CGRect originRect = CGRectMake(sharedViewFrameOrigin.x, sharedViewFrameOrigin.y, view.frame.size.width, view.frame.size.height);
  34. return originRect;
  35. }
  36. - (CGPoint)centerFromSuperViewController:(UIView *)view andVC:(UIViewController *)vc{
  37. CGPoint sharedViewFrameOrigin = [view.superview convertPoint:view.frame.origin toView:vc.view];
  38. CGRect originRect = CGRectMake(sharedViewFrameOrigin.x, sharedViewFrameOrigin.y, view.frame.size.width, view.frame.size.height);
  39. CGFloat x = originRect.origin.x + view.frame.size.width/2;
  40. CGFloat y = originRect.origin.y + view.frame.size.height/2;
  41. CGPoint center = CGPointMake(x, y);
  42. return center;
  43. }
  44. @end