react-native-navigation的迁移库

RNNViewLocation.m 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #import "RNNViewLocation.h"
  2. @implementation RNNViewLocation
  3. -(instancetype)initWithTransition:(RNNTransitionStateHolder*)transition andVC:(UIViewController*)vc {
  4. self = [super init];
  5. self.fromFrame = [self frameFromSuperViewController:[transition.fromElement subviews][0] andVC:vc];
  6. CGSize fromSize = self.fromFrame.size;
  7. CGPoint fromCenter = [self centerFromSuperViewController:[transition.fromElement subviews][0] andVC:vc];
  8. fromCenter.x = fromCenter.x + transition.startX;
  9. fromCenter.y = fromCenter.y + transition.startY;
  10. self.fromCenter = fromCenter;
  11. CGRect toFrame = [self frameFromSuperViewController:[transition.fromElement subviews][0] andVC:vc];
  12. CGSize toSize = self.fromFrame.size;
  13. CGPoint toCenter = [self centerFromSuperViewController:[transition.fromElement subviews][0] andVC:vc];
  14. if (transition.toElement) {
  15. toFrame = [self frameFromSuperViewController:[transition.toElement subviews][0] andVC:vc];
  16. toSize = toFrame.size;
  17. toCenter = [self centerFromSuperViewController:[transition.toElement subviews][0] andVC:vc];
  18. }
  19. toCenter.x = toCenter.x + transition.endX;
  20. toCenter.y = toCenter.y + transition.endY;
  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