react-native-navigation的迁移库

MMExampleDrawerVisualStateManager.m 4.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/)
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. #import "MMExampleDrawerVisualStateManager.h"
  21. #import <QuartzCore/QuartzCore.h>
  22. @implementation MMExampleDrawerVisualStateManager
  23. + (MMExampleDrawerVisualStateManager *)sharedManager {
  24. static MMExampleDrawerVisualStateManager *_sharedManager = nil;
  25. static dispatch_once_t onceToken;
  26. dispatch_once(&onceToken, ^{
  27. _sharedManager = [[MMExampleDrawerVisualStateManager alloc] init];
  28. [_sharedManager setLeftDrawerAnimationType:MMDrawerAnimationTypeParallax];
  29. [_sharedManager setRightDrawerAnimationType:MMDrawerAnimationTypeParallax];
  30. });
  31. return _sharedManager;
  32. }
  33. -(MMDrawerControllerDrawerVisualStateBlock)drawerVisualStateBlockForDrawerSide:(MMDrawerSide)drawerSide{
  34. MMDrawerAnimationType animationType;
  35. if(drawerSide == MMDrawerSideLeft){
  36. animationType = self.leftDrawerAnimationType;
  37. }
  38. else {
  39. animationType = self.rightDrawerAnimationType;
  40. }
  41. MMDrawerControllerDrawerVisualStateBlock visualStateBlock = nil;
  42. switch (animationType) {
  43. case MMDrawerAnimationTypeSlide:
  44. visualStateBlock = [MMDrawerVisualState slideVisualStateBlock];
  45. break;
  46. case MMDrawerAnimationTypeSlideAndScale:
  47. visualStateBlock = [MMDrawerVisualState slideAndScaleVisualStateBlock];
  48. break;
  49. case MMDrawerAnimationTypeParallax:
  50. visualStateBlock = [MMDrawerVisualState parallaxVisualStateBlockWithParallaxFactor:2.0];
  51. break;
  52. case MMDrawerAnimationTypeSwingingDoor:
  53. visualStateBlock = [MMDrawerVisualState swingingDoorVisualStateBlock];
  54. break;
  55. default:
  56. visualStateBlock = ^(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible){
  57. UIViewController * sideDrawerViewController;
  58. CATransform3D transform;
  59. CGFloat maxDrawerWidth = 0;
  60. if(drawerSide == MMDrawerSideLeft){
  61. sideDrawerViewController = drawerController.leftDrawerViewController;
  62. maxDrawerWidth = drawerController.maximumLeftDrawerWidth;
  63. }
  64. else if(drawerSide == MMDrawerSideRight){
  65. sideDrawerViewController = drawerController.rightDrawerViewController;
  66. maxDrawerWidth = drawerController.maximumRightDrawerWidth;
  67. }
  68. if(percentVisible > 1.0){
  69. transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f);
  70. if(drawerSide == MMDrawerSideLeft){
  71. transform = CATransform3DTranslate(transform, maxDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f);
  72. }else if(drawerSide == MMDrawerSideRight){
  73. transform = CATransform3DTranslate(transform, -maxDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f);
  74. }
  75. }
  76. else {
  77. transform = CATransform3DIdentity;
  78. }
  79. [sideDrawerViewController.view.layer setTransform:transform];
  80. };
  81. break;
  82. }
  83. return visualStateBlock;
  84. }
  85. @end