react-native-navigation的迁移库

SidebarLuvocracyAnimation.m 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SidebarLuvocracyAnimation.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 "SidebarLuvocracyAnimation.h"
  24. @implementation SidebarLuvocracyAnimation
  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 sidebar 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. }
  44. else
  45. {
  46. contentTransform = CATransform3DTranslate(contentTransform, 0 - visibleWidth + (contentView.frame.size.width / 2 * 0.4), 0.0, 0.0);
  47. contentTransform = CATransform3DScale(contentTransform, 0.6, 0.6, 0.6);
  48. }
  49. UIView *overlayContentView = [self overlayContentView:contentView.bounds];
  50. [contentView addSubview:overlayContentView];
  51. // Animate
  52. [UIView animateWithDuration:animationDuration
  53. delay:0.0
  54. options:UIViewAnimationOptionCurveEaseInOut
  55. animations:^{
  56. contentView.layer.transform = contentTransform;
  57. sidebarView.layer.transform = sidebarTransform;
  58. overlayContentView.backgroundColor = [self overlayContentColor];
  59. }
  60. completion:^(BOOL finished) {
  61. completion(finished);
  62. }];
  63. }
  64. + (void)reverseAnimateContentView:(UIView *)contentView sidebarView:(UIView *)sidebarView fromSide:(Side)side visibleWidth:(CGFloat)visibleWidth duration:(NSTimeInterval)animationDuration completion:(void (^)(BOOL))completion
  65. {
  66. // Animation settings for content view
  67. CATransform3D contentTransform = CATransform3DIdentity;
  68. contentTransform.m34 = -1.0f / 800.0f;
  69. contentView.layer.zPosition = 100;
  70. contentTransform = CATransform3DTranslate(contentTransform, 0.0, 0.0, 0.0);
  71. contentTransform = CATransform3DScale(contentTransform, 1.0, 1.0, 1.0);
  72. // Animation settings for menu view
  73. __block CATransform3D sidebarTransform = CATransform3DIdentity;
  74. sidebarTransform = CATransform3DScale(sidebarTransform, 1.7, 1.7, 1.7);
  75. UIView *overlayContentView = [self overlayContentView:contentView.bounds];
  76. [contentView addSubview:overlayContentView];
  77. // Animate
  78. [UIView animateWithDuration:animationDuration
  79. delay:0.0
  80. options:UIViewAnimationOptionCurveEaseInOut
  81. animations:^{
  82. contentView.layer.transform = contentTransform;
  83. sidebarView.layer.transform = sidebarTransform;
  84. overlayContentView.backgroundColor = [UIColor clearColor];
  85. }
  86. completion:^(BOOL finished) {
  87. completion(finished);
  88. sidebarTransform = CATransform3DIdentity;
  89. sidebarTransform = CATransform3DScale(sidebarTransform, 1.0, 1.0, 1.0);
  90. sidebarView.layer.transform = sidebarTransform;
  91. [overlayContentView removeFromSuperview];
  92. }];
  93. }
  94. @end