react-native-navigation的迁移库

RNNAnimatedView.m 2.6KB

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