react-native-navigation的迁移库

RNNAnimatedView.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #import "RNNAnimatedView.h"
  2. #import "RNNElementView.h"
  3. @implementation RNNAnimatedView
  4. -(instancetype)initFromElement:(RNNElementView*)fromElement toElement:(RNNElementView*)toElement andLocation:(RNNViewLocation*)location andIsBackButton:(BOOL)backButton startAlpha:(CGFloat)startAlpha endAlpha:(CGFloat)endAlpha {
  5. UIView* animatedView = nil;
  6. if (backButton) {
  7. if ([self elementIsImage:fromElement]) {
  8. animatedView = [self createImageAnimatedView:animatedView fromElement:fromElement toElement:toElement];
  9. } else {
  10. if (toElement) {
  11. animatedView = [[toElement subviews][0] snapshotViewAfterScreenUpdates:NO];
  12. } else {
  13. animatedView = [[fromElement subviews][0] snapshotViewAfterScreenUpdates:NO];
  14. }
  15. }
  16. [self assignStyle:animatedView withSize:location.toSize center:location.toCenter andAlpha:endAlpha];
  17. } else {
  18. if ([self elementIsImage:fromElement]) {
  19. animatedView = [self createImageAnimatedView:animatedView fromElement:fromElement toElement:fromElement];
  20. } else {
  21. animatedView = [[fromElement subviews][0] snapshotViewAfterScreenUpdates:YES];
  22. }
  23. [self assignStyle:animatedView withSize:location.fromSize center:location.fromCenter andAlpha:startAlpha];
  24. }
  25. return (RNNAnimatedView*)animatedView;
  26. }
  27. -(BOOL)elementIsImage:(RNNElementView*)element {
  28. return [[element subviews][0] isKindOfClass:[UIImageView class]];
  29. }
  30. -(UIView*)createImageAnimatedView:(UIView*)animatedView fromElement:(RNNElementView*)fromElement toElement:(RNNElementView*)toElement {
  31. UIImage* image = [[fromElement subviews][0] image];
  32. animatedView = [[VICMAImageView alloc] initWithImage:image];
  33. animatedView.contentMode = UIViewContentModeScaleAspectFill;
  34. if (toElement.resizeMode){
  35. animatedView.contentMode = [RNNAnimatedView contentModefromString:toElement.resizeMode];
  36. }
  37. return animatedView;
  38. }
  39. -(void)assignStyle:(UIView*)animatedView withSize:(CGSize)size center:(CGPoint)center andAlpha:(double)alpha {
  40. animatedView.frame = CGRectMake(0, 0, size.width, size.height);
  41. animatedView.center = center;
  42. animatedView.alpha = alpha;
  43. }
  44. +(UIViewContentMode)contentModefromString:(NSString*)resizeMode{
  45. if ([resizeMode isEqualToString:@"cover"]) {
  46. return UIViewContentModeScaleAspectFill;
  47. } else if ([resizeMode isEqualToString:@"contain"]) {
  48. return UIViewContentModeScaleAspectFit;
  49. } else if ([resizeMode isEqualToString:@"stretch"]) {
  50. return UIViewContentModeScaleToFill;
  51. } else {
  52. return 0;
  53. }
  54. }
  55. @end