react-native-navigation的迁移库

RCCDrawerHelper.m 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // RCCDrawerHelper.m
  3. // ReactNativeControllers
  4. //
  5. // Created by Ran Greenberg on 07/04/2016.
  6. // Copyright © 2016 artal. All rights reserved.
  7. //
  8. #import "RCCDrawerHelper.h"
  9. @implementation RCCDrawerHelper
  10. static CGFloat _sideMenuWidth;
  11. +(UIButton*)createOverlayButton:(id)target {
  12. UIButton *overlayButton = [[UIButton alloc] init];
  13. overlayButton.backgroundColor = [UIColor clearColor];
  14. [overlayButton addTarget:target action:@selector(overlayButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  15. return overlayButton;
  16. }
  17. +(void)addOverlayButtonToScreen:(UIButton*)buttonToAdd
  18. contextView:(UIView*)view
  19. side:(RCCDrawerSide)side
  20. sideMenuWidth:(CGFloat)sideMenuWidth
  21. animationDuration:(CGFloat)duration {
  22. _sideMenuWidth = sideMenuWidth;
  23. CGRect buttonFrame = view.bounds;
  24. buttonFrame.origin.x = [RCCDrawerHelper overlayButtonX:sideMenuWidth side:side];
  25. switch (side) {
  26. case RCCDrawerSideLeft:
  27. {
  28. buttonFrame.origin.x = sideMenuWidth;
  29. }
  30. break;
  31. case RCCDrawerSideRight:
  32. {
  33. buttonFrame.origin.x = 0;
  34. }
  35. break;
  36. default:
  37. break;
  38. }
  39. buttonFrame.size.width = buttonFrame.size.width - sideMenuWidth;
  40. buttonToAdd.frame = buttonFrame;
  41. [view addSubview:buttonToAdd];
  42. }
  43. +(void)overlayButtonPressed:(UIButton*)button animationDuration:(CGFloat)duration {
  44. [button removeFromSuperview];
  45. }
  46. +(CGFloat)overlayButtonX:(CGFloat)sideMenuWidth side:(RCCDrawerSide)side {
  47. switch (side) {
  48. case RCCDrawerSideLeft:
  49. {
  50. return sideMenuWidth;
  51. }
  52. break;
  53. case RCCDrawerSideRight:
  54. {
  55. return 0;
  56. }
  57. break;
  58. default:
  59. break;
  60. }
  61. }
  62. + (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
  63. //UIGraphicsBeginImageContext(newSize);
  64. // In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
  65. // Pass 1.0 to force exact pixel size.
  66. UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
  67. [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
  68. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  69. UIGraphicsEndImageContext();
  70. return newImage;
  71. }
  72. @end