react-native-navigation的迁移库

TransformRectTransition.m 1.5KB

12345678910111213141516171819202122232425262728293031
  1. #import "TransformRectTransition.h"
  2. @implementation TransformRectTransition
  3. - (instancetype)initWithView:(UIView *)view fromRect:(CGRect)fromRect toRect:(CGRect)toRect fromAngle:(CGFloat)fromAngle toAngle:(CGFloat)toAngle startDelay:(NSTimeInterval)startDelay duration:(NSTimeInterval)duration interpolation:(Text *)interpolation {
  4. self = [super initWithView:view from:fromRect to:toRect startDelay:startDelay duration:duration interpolation:interpolation];
  5. _fromAngle = fromAngle;
  6. _toAngle = toAngle;
  7. return self;
  8. }
  9. - (CATransform3D)animateWithProgress:(CGFloat)p {
  10. CGRect toFrame = [RNNInterpolator fromRect:self.from toRect:self.to precent:p interpolation:self.interpolation];
  11. CGFloat toAngle = [RNNInterpolator fromFloat:self.fromAngle toFloat:self.toAngle precent:p interpolation:self.interpolation];
  12. CGFloat scaleX = toFrame.size.width / self.from.size.width;
  13. CGFloat scaleY = toFrame.size.height / self.from.size.height;
  14. CGFloat offsetX = toFrame.origin.x - self.from.origin.x;
  15. CGFloat offsetY = toFrame.origin.y - self.from.origin.y;
  16. CGFloat translateX = (offsetX + (toFrame.size.width - self.from.size.width)/2);
  17. CGFloat translateY = (offsetY + (toFrame.size.height - self.from.size.height)/2);
  18. CATransform3D translate = CATransform3DMakeTranslation(translateX, translateY, 0);
  19. CATransform3D scale = CATransform3DScale(translate, scaleX, scaleY, 0);
  20. CATransform3D rotate = CATransform3DRotate(scale, toAngle, 0, 0, 1);
  21. return rotate;
  22. }
  23. @end