react-native-navigation的迁移库

SidebarAirbnbAnimation.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // SidebarAirbnbAnimation.m
  2. // TheSidebarController
  3. //
  4. // Copyright (c) 2014 Jon Danao (danao.org | jondanao)
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. #import "SidebarAirbnbAnimation.h"
  24. @implementation SidebarAirbnbAnimation
  25. + (void)animateContentView:(UIView *)contentView sidebarView:(UIView *)sidebarView fromSide:(Side)side visibleWidth:(CGFloat)visibleWidth duration:(NSTimeInterval)animationDuration completion:(void (^)(BOOL))completion
  26. {
  27. [self resetSidebarPosition:sidebarView];
  28. [self resetContentPosition:contentView];
  29. // Animation settings for content view
  30. CATransform3D contentTransform = CATransform3DIdentity;
  31. contentTransform.m34 = -1.0f / 800.0f;
  32. contentView.layer.zPosition = 100;
  33. // Animation settings for menu view
  34. CATransform3D sidebarTransform = CATransform3DIdentity;
  35. sidebarTransform = CATransform3DScale(sidebarTransform, 1.7, 1.7, 1.7);
  36. sidebarView.layer.transform = sidebarTransform;
  37. sidebarTransform = CATransform3DIdentity;
  38. sidebarTransform = CATransform3DScale(sidebarTransform, 1.0, 1.0, 1.0);
  39. if(side == LeftSide)
  40. {
  41. contentTransform = CATransform3DTranslate(contentTransform, visibleWidth - (contentView.frame.size.width / 2 * 0.4), 0.0, 0.0);
  42. contentTransform = CATransform3DScale(contentTransform, 0.6, 0.6, 0.6);
  43. contentTransform = CATransform3DRotate(contentTransform, DEG2RAD(-45), 0.0, 1.0, 0.0);
  44. }
  45. else
  46. {
  47. contentTransform = CATransform3DTranslate(contentTransform, 0 - visibleWidth + (contentView.frame.size.width / 2 * 0.4), 0.0, 0.0);
  48. contentTransform = CATransform3DScale(contentTransform, 0.6, 0.6, 0.6);
  49. contentTransform = CATransform3DRotate(contentTransform, DEG2RAD(45), 0.0, 1.0, 0.0);
  50. }
  51. UIView *overlayContentView = [self overlayContentView:contentView.bounds];
  52. [contentView addSubview:overlayContentView];
  53. // Animate content view
  54. [UIView animateWithDuration:animationDuration
  55. delay:0.0
  56. options:UIViewAnimationOptionCurveEaseInOut
  57. animations:^{
  58. contentView.layer.transform = contentTransform;
  59. overlayContentView.backgroundColor = [self overlayContentColor];
  60. }
  61. completion:^(BOOL finished) {
  62. completion(finished);
  63. }];
  64. // Animate menu view
  65. [UIView animateWithDuration:animationDuration
  66. delay:0.0
  67. options:UIViewAnimationOptionCurveEaseInOut
  68. animations:^{
  69. sidebarView.layer.transform = sidebarTransform;
  70. }
  71. completion:nil];
  72. }
  73. + (void)reverseAnimateContentView:(UIView *)contentView sidebarView:(UIView *)sidebarView fromSide:(Side)side visibleWidth:(CGFloat)visibleWidth duration:(NSTimeInterval)animationDuration completion:(void (^)(BOOL))completion
  74. {
  75. // Animation settings for content view
  76. CATransform3D contentTransform = CATransform3DIdentity;
  77. contentTransform.m34 = -1.0f / 800.0f;
  78. contentView.layer.zPosition = 100;
  79. contentTransform = CATransform3DTranslate(contentTransform, 0.0, 0.0, 0.0);
  80. contentTransform = CATransform3DScale(contentTransform, 1.0, 1.0, 1.0);
  81. contentTransform = CATransform3DRotate(contentTransform, DEG2RAD(0), 0.0, 1.0, 0.0);
  82. // Animation settings for menu view
  83. __block CATransform3D sidebarTransform = CATransform3DIdentity;
  84. sidebarTransform = CATransform3DScale(sidebarTransform, 1.7, 1.7, 1.7);
  85. UIView *overlayContentView = [self overlayContentView:contentView.bounds];
  86. [contentView addSubview:overlayContentView];
  87. // Animate content view
  88. [UIView animateWithDuration:animationDuration
  89. delay:0.0
  90. options:UIViewAnimationOptionCurveEaseInOut
  91. animations:^{
  92. contentView.layer.transform = contentTransform;
  93. overlayContentView.backgroundColor = [UIColor clearColor];
  94. }
  95. completion:^(BOOL finished) {
  96. completion(finished);
  97. }];
  98. // Animate menu view
  99. [UIView animateWithDuration:animationDuration
  100. delay:0.0
  101. options:UIViewAnimationOptionCurveEaseInOut
  102. animations:^{
  103. sidebarView.layer.transform = sidebarTransform;
  104. }
  105. completion:^(BOOL finished) {
  106. sidebarTransform = CATransform3DIdentity;
  107. sidebarTransform = CATransform3DScale(sidebarTransform, 1.0, 1.0, 1.0);
  108. sidebarView.layer.transform = sidebarTransform;
  109. [overlayContentView removeFromSuperview];
  110. }];
  111. }
  112. @end