react-native-navigation的迁移库

MMDrawerController.m 63KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  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 "MMDrawerController.h"
  21. #import "UIViewController+MMDrawerController.h"
  22. #import <QuartzCore/QuartzCore.h>
  23. CGFloat const MMDrawerDefaultWidth = 280.0f;
  24. CGFloat const MMDrawerDefaultAnimationVelocity = 840.0f;
  25. NSTimeInterval const MMDrawerDefaultFullAnimationDelay = 0.10f;
  26. CGFloat const MMDrawerDefaultBounceDistance = 50.0f;
  27. NSTimeInterval const MMDrawerDefaultBounceAnimationDuration = 0.2f;
  28. CGFloat const MMDrawerDefaultSecondBounceDistancePercentage = .25f;
  29. CGFloat const MMDrawerDefaultShadowRadius = 10.0f;
  30. CGFloat const MMDrawerDefaultShadowOpacity = 0.8;
  31. NSTimeInterval const MMDrawerMinimumAnimationDuration = 0.15f;
  32. CGFloat const MMDrawerBezelRange = 20.0f;
  33. CGFloat const MMDrawerPanVelocityXAnimationThreshold = 200.0f;
  34. /** The amount of overshoot that is panned linearly. The remaining percentage nonlinearly asymptotes to the max percentage. */
  35. CGFloat const MMDrawerOvershootLinearRangePercentage = 0.75f;
  36. /** The percent of the possible overshoot width to use as the actual overshoot percentage. */
  37. CGFloat const MMDrawerOvershootPercentage = 0.1f;
  38. typedef void (^MMDrawerGestureStartedBlock)(MMDrawerController * drawerController, UIGestureRecognizer * gesture);
  39. typedef BOOL (^MMDrawerGestureShouldRecognizeTouchBlock)(MMDrawerController * drawerController, UIGestureRecognizer * gesture, UITouch * touch);
  40. typedef void (^MMDrawerGestureCompletionBlock)(MMDrawerController * drawerController, UIGestureRecognizer * gesture);
  41. static CAKeyframeAnimation * bounceKeyFrameAnimationForDistanceOnView(CGFloat distance, UIView * view) {
  42. CGFloat factors[32] = {0, 32, 60, 83, 100, 114, 124, 128, 128, 124, 114, 100, 83, 60, 32,
  43. 0, 24, 42, 54, 62, 64, 62, 54, 42, 24, 0, 18, 28, 32, 28, 18, 0};
  44. NSMutableArray *values = [NSMutableArray array];
  45. for (int i=0; i<32; i++)
  46. {
  47. CGFloat positionOffset = factors[i]/128.0f * distance + CGRectGetMidX(view.bounds);
  48. [values addObject:@(positionOffset)];
  49. }
  50. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
  51. animation.repeatCount = 1;
  52. animation.duration = .8;
  53. animation.fillMode = kCAFillModeForwards;
  54. animation.values = values;
  55. animation.removedOnCompletion = YES;
  56. animation.autoreverses = NO;
  57. return animation;
  58. }
  59. static NSString *MMDrawerLeftDrawerKey = @"MMDrawerLeftDrawer";
  60. static NSString *MMDrawerRightDrawerKey = @"MMDrawerRightDrawer";
  61. static NSString *MMDrawerCenterKey = @"MMDrawerCenter";
  62. static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
  63. @interface MMDrawerCenterContainerView : UIView
  64. @property (nonatomic,assign) MMDrawerOpenCenterInteractionMode centerInteractionMode;
  65. @property (nonatomic,assign) MMDrawerSide openSide;
  66. @property (nonatomic, strong) UIView *overlayView;
  67. @end
  68. @implementation MMDrawerCenterContainerView
  69. -(UIView *)overlayView {
  70. if (!_overlayView) {
  71. _overlayView = [[UIView alloc] initWithFrame:self.bounds];
  72. _overlayView.userInteractionEnabled = NO;
  73. _overlayView.alpha = 0.0;
  74. }
  75. return _overlayView;
  76. }
  77. -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
  78. UIView *hitView = [super hitTest:point withEvent:event];
  79. if(hitView &&
  80. self.openSide != MMDrawerSideNone){
  81. UINavigationBar * navBar = [self navigationBarContainedWithinSubviewsOfView:self];
  82. CGRect navBarFrame = [navBar convertRect:navBar.bounds toView:self];
  83. if((self.centerInteractionMode == MMDrawerOpenCenterInteractionModeNavigationBarOnly &&
  84. CGRectContainsPoint(navBarFrame, point) == NO) ||
  85. self.centerInteractionMode == MMDrawerOpenCenterInteractionModeNone){
  86. hitView = nil;
  87. }
  88. }
  89. return hitView;
  90. }
  91. -(UINavigationBar*)navigationBarContainedWithinSubviewsOfView:(UIView*)view{
  92. UINavigationBar * navBar = nil;
  93. for(UIView * subview in [view subviews]){
  94. if([view isKindOfClass:[UINavigationBar class]]){
  95. navBar = (UINavigationBar*)view;
  96. break;
  97. }
  98. else {
  99. navBar = [self navigationBarContainedWithinSubviewsOfView:subview];
  100. if (navBar != nil) {
  101. break;
  102. }
  103. }
  104. }
  105. return navBar;
  106. }
  107. -(void)setFrame:(CGRect)frame withLayoutAlpha:(CGFloat)layoutAlpha {
  108. [super setFrame:frame];
  109. self.overlayView.alpha = layoutAlpha;
  110. if (![self.overlayView isDescendantOfView:self]) {
  111. [self addSubview:self.overlayView];
  112. }
  113. else {
  114. [self bringSubviewToFront:self.overlayView];
  115. }
  116. }
  117. @end
  118. @interface MMDrawerController () <UIGestureRecognizerDelegate>{
  119. CGFloat _maximumRightDrawerWidth;
  120. CGFloat _maximumLeftDrawerWidth;
  121. UIColor * _statusBarViewBackgroundColor;
  122. }
  123. @property (nonatomic, assign, readwrite) MMDrawerSide openSide;
  124. @property (nonatomic, strong) UIView * childControllerContainerView;
  125. @property (nonatomic, strong) MMDrawerCenterContainerView * centerContainerView;
  126. @property (nonatomic, strong) UIView * dummyStatusBarView;
  127. @property (nonatomic, assign) CGRect startingPanRect;
  128. @property (nonatomic, copy) MMDrawerControllerDrawerVisualStateBlock drawerVisualState;
  129. @property (nonatomic, copy) MMDrawerGestureShouldRecognizeTouchBlock gestureShouldRecognizeTouch;
  130. @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureStart;
  131. @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureCompletion;
  132. @property (nonatomic, assign, getter = isAnimatingDrawer) BOOL animatingDrawer;
  133. @end
  134. @implementation MMDrawerController
  135. #pragma mark - Init
  136. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  137. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  138. if (self) {
  139. [self commonSetup];
  140. }
  141. return self;
  142. }
  143. - (id)initWithCoder:(NSCoder *)aDecoder{
  144. self = [super initWithCoder:aDecoder];
  145. if (self) {
  146. [self commonSetup];
  147. }
  148. return self;
  149. }
  150. -(instancetype)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController{
  151. NSParameterAssert(centerViewController);
  152. self = [super init];
  153. if(self){
  154. [self setCenterViewController:centerViewController];
  155. [self setLeftDrawerViewController:leftDrawerViewController];
  156. [self setRightDrawerViewController:rightDrawerViewController];
  157. }
  158. return self;
  159. }
  160. -(instancetype)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController{
  161. return [self initWithCenterViewController:centerViewController leftDrawerViewController:leftDrawerViewController rightDrawerViewController:nil];
  162. }
  163. -(instancetype)initWithCenterViewController:(UIViewController *)centerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController{
  164. return [self initWithCenterViewController:centerViewController leftDrawerViewController:nil rightDrawerViewController:rightDrawerViewController];
  165. }
  166. -(void)commonSetup{
  167. [self setMaximumLeftDrawerWidth:MMDrawerDefaultWidth];
  168. [self setMaximumRightDrawerWidth:MMDrawerDefaultWidth];
  169. [self setAnimationVelocity:MMDrawerDefaultAnimationVelocity];
  170. [self setShowsShadow:YES];
  171. [self setShouldStretchDrawer:YES];
  172. [self setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
  173. [self setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];
  174. [self setCenterHiddenInteractionMode:MMDrawerOpenCenterInteractionModeNavigationBarOnly];
  175. // set shadow related default values
  176. [self setShadowOpacity:MMDrawerDefaultShadowOpacity];
  177. [self setShadowRadius:MMDrawerDefaultShadowRadius];
  178. [self setShadowOffset:CGSizeMake(0, -3)];
  179. [self setShadowColor:[UIColor blackColor]];
  180. // set default bezel range for panGestureReconizer
  181. [self setBezelPanningCenterViewRange:MMDrawerBezelRange];
  182. // set defualt panVelocityXAnimationThreshold
  183. [self setPanVelocityXAnimationThreshold:MMDrawerPanVelocityXAnimationThreshold];
  184. _rightSideEnabled = _leftSideEnabled = YES;
  185. }
  186. #pragma mark - State Restoration
  187. - (void)encodeRestorableStateWithCoder:(NSCoder *)coder{
  188. [super encodeRestorableStateWithCoder:coder];
  189. if (self.leftDrawerViewController){
  190. [coder encodeObject:self.leftDrawerViewController forKey:MMDrawerLeftDrawerKey];
  191. }
  192. if (self.rightDrawerViewController){
  193. [coder encodeObject:self.rightDrawerViewController forKey:MMDrawerRightDrawerKey];
  194. }
  195. if (self.centerViewController){
  196. [coder encodeObject:self.centerViewController forKey:MMDrawerCenterKey];
  197. }
  198. [coder encodeInteger:self.openSide forKey:MMDrawerOpenSideKey];
  199. }
  200. - (void)decodeRestorableStateWithCoder:(NSCoder *)coder{
  201. UIViewController *controller;
  202. MMDrawerSide openside;
  203. [super decodeRestorableStateWithCoder:coder];
  204. if ((controller = [coder decodeObjectForKey:MMDrawerLeftDrawerKey])){
  205. self.leftDrawerViewController = controller;
  206. }
  207. if ((controller = [coder decodeObjectForKey:MMDrawerRightDrawerKey])){
  208. self.rightDrawerViewController = controller;
  209. }
  210. if ((controller = [coder decodeObjectForKey:MMDrawerCenterKey])){
  211. self.centerViewController = controller;
  212. }
  213. if ((openside = [coder decodeIntegerForKey:MMDrawerOpenSideKey])){
  214. [self openDrawerSide:openside animated:false completion:nil];
  215. }
  216. }
  217. #pragma mark - Open/Close methods
  218. -(void)toggleDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void (^)(BOOL finished))completion{
  219. NSParameterAssert(drawerSide!=MMDrawerSideNone);
  220. if(self.openSide == MMDrawerSideNone){
  221. [self openDrawerSide:drawerSide animated:animated completion:completion];
  222. }
  223. else {
  224. if((drawerSide == MMDrawerSideLeft &&
  225. self.openSide == MMDrawerSideLeft) ||
  226. (drawerSide == MMDrawerSideRight &&
  227. self.openSide == MMDrawerSideRight)){
  228. [self closeDrawerAnimated:animated completion:completion];
  229. }
  230. else if(completion){
  231. completion(NO);
  232. }
  233. }
  234. }
  235. -(void)closeDrawerAnimated:(BOOL)animated completion:(void (^)(BOOL finished))completion{
  236. [self closeDrawerAnimated:animated velocity:self.animationVelocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion];
  237. }
  238. -(void)closeDrawerAnimated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion{
  239. if(self.isAnimatingDrawer){
  240. if(completion){
  241. completion(NO);
  242. }
  243. }
  244. else {
  245. [self setAnimatingDrawer:animated];
  246. CGRect newFrame = self.childControllerContainerView.bounds;
  247. CGFloat distance = ABS(CGRectGetMinX(self.centerContainerView.frame));
  248. NSTimeInterval duration = MAX(distance/ABS(velocity),MMDrawerMinimumAnimationDuration);
  249. BOOL leftDrawerVisible = CGRectGetMinX(self.centerContainerView.frame) > 0;
  250. BOOL rightDrawerVisible = CGRectGetMinX(self.centerContainerView.frame) < 0;
  251. MMDrawerSide visibleSide = MMDrawerSideNone;
  252. CGFloat percentVisble = 0.0;
  253. if(leftDrawerVisible){
  254. CGFloat visibleDrawerPoints = CGRectGetMinX(self.centerContainerView.frame);
  255. percentVisble = MAX(0.0,visibleDrawerPoints/self.maximumLeftDrawerWidth);
  256. visibleSide = MMDrawerSideLeft;
  257. }
  258. else if(rightDrawerVisible){
  259. CGFloat visibleDrawerPoints = CGRectGetWidth(self.centerContainerView.frame)-CGRectGetMaxX(self.centerContainerView.frame);
  260. percentVisble = MAX(0.0,visibleDrawerPoints/self.maximumRightDrawerWidth);
  261. visibleSide = MMDrawerSideRight;
  262. }
  263. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:visibleSide];
  264. [self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:percentVisble];
  265. [sideDrawerViewController beginAppearanceTransition:NO animated:animated];
  266. [UIView
  267. animateWithDuration:(animated?duration:0.0)
  268. delay:0.0
  269. options:options
  270. animations:^{
  271. [self setNeedsStatusBarAppearanceUpdateIfSupported];
  272. [self.centerContainerView setFrame:newFrame withLayoutAlpha:0.0];
  273. [self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:0.0];
  274. }
  275. completion:^(BOOL finished) {
  276. [sideDrawerViewController endAppearanceTransition];
  277. [self setOpenSide:MMDrawerSideNone];
  278. [self resetDrawerVisualStateForDrawerSide:visibleSide];
  279. [self setAnimatingDrawer:NO];
  280. if(completion){
  281. completion(finished);
  282. }
  283. }];
  284. }
  285. }
  286. -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void (^)(BOOL finished))completion{
  287. NSParameterAssert(drawerSide != MMDrawerSideNone);
  288. [self openDrawerSide:drawerSide animated:animated velocity:self.animationVelocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion];
  289. }
  290. -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion{
  291. NSParameterAssert(drawerSide != MMDrawerSideNone);
  292. if (self.isAnimatingDrawer) {
  293. if(completion){
  294. completion(NO);
  295. }
  296. }
  297. else {
  298. [self setAnimatingDrawer:animated];
  299. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  300. if (self.openSide != drawerSide) {
  301. [self prepareToPresentDrawer:drawerSide animated:animated];
  302. }
  303. if(sideDrawerViewController){
  304. CGRect newFrame;
  305. CGRect oldFrame = self.centerContainerView.frame;
  306. if(drawerSide == MMDrawerSideLeft){
  307. newFrame = self.centerContainerView.frame;
  308. newFrame.origin.x = self.maximumLeftDrawerWidth;
  309. }
  310. else {
  311. newFrame = self.centerContainerView.frame;
  312. newFrame.origin.x = 0-self.maximumRightDrawerWidth;
  313. }
  314. CGFloat distance = ABS(CGRectGetMinX(oldFrame)-newFrame.origin.x);
  315. NSTimeInterval duration = MAX(distance/ABS(velocity),MMDrawerMinimumAnimationDuration);
  316. [UIView
  317. animateWithDuration:(animated?duration:0.0)
  318. delay:0.0
  319. options:options
  320. animations:^{
  321. [self setNeedsStatusBarAppearanceUpdateIfSupported];
  322. [self.centerContainerView setFrame:newFrame withLayoutAlpha:1.0];
  323. [self updateDrawerVisualStateForDrawerSide:drawerSide percentVisible:1.0];
  324. }
  325. completion:^(BOOL finished) {
  326. //End the appearance transition if it already wasn't open.
  327. if(drawerSide != self.openSide){
  328. [sideDrawerViewController endAppearanceTransition];
  329. }
  330. [self setOpenSide:drawerSide];
  331. [self resetDrawerVisualStateForDrawerSide:drawerSide];
  332. [self setAnimatingDrawer:NO];
  333. if(completion){
  334. completion(finished);
  335. }
  336. }];
  337. }
  338. }
  339. }
  340. #pragma mark - Updating the Center View Controller
  341. //If animated is NO, then we need to handle all the appearance calls within this method. Otherwise,
  342. //let the method calling this one handle proper appearance methods since they will have more context
  343. -(void)setCenterViewController:(UIViewController *)centerViewController animated:(BOOL)animated{
  344. if ([self.centerViewController isEqual:centerViewController]) {
  345. return;
  346. }
  347. if (_centerContainerView == nil) {
  348. //This is related to Issue #152 (https://github.com/mutualmobile/MMDrawerController/issues/152)
  349. // also fixed below in the getter for `childControllerContainerView`. Turns out we have
  350. // two center container views getting added to the view during init,
  351. // because the first request self.centerContainerView.bounds was kicking off a
  352. // viewDidLoad, which caused us to be able to fall through this check twice.
  353. //
  354. //The fix is to grab the bounds, and then check again that the child container view has
  355. //not been created.
  356. CGRect centerFrame = self.childControllerContainerView.bounds;
  357. if(_centerContainerView == nil){
  358. _centerContainerView = [[MMDrawerCenterContainerView alloc] initWithFrame:centerFrame];
  359. [self.centerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
  360. [self.centerContainerView setBackgroundColor:[UIColor clearColor]];
  361. [self.centerContainerView setOpenSide:self.openSide];
  362. [self.centerContainerView setCenterInteractionMode:self.centerHiddenInteractionMode];
  363. [self.childControllerContainerView addSubview:self.centerContainerView];
  364. }
  365. }
  366. UIViewController * oldCenterViewController = self.centerViewController;
  367. if(oldCenterViewController){
  368. [oldCenterViewController willMoveToParentViewController:nil];
  369. if(animated == NO){
  370. [oldCenterViewController beginAppearanceTransition:NO animated:NO];
  371. }
  372. [oldCenterViewController.view removeFromSuperview];
  373. if(animated == NO){
  374. [oldCenterViewController endAppearanceTransition];
  375. }
  376. [oldCenterViewController removeFromParentViewController];
  377. }
  378. _centerViewController = centerViewController;
  379. [self addChildViewController:self.centerViewController];
  380. [self.centerViewController.view setFrame:self.childControllerContainerView.bounds];
  381. [self.centerContainerView addSubview:self.centerViewController.view];
  382. [self.childControllerContainerView bringSubviewToFront:self.centerContainerView];
  383. [self.centerViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
  384. [self updateShadowForCenterView];
  385. if(animated == NO){
  386. // If drawer is offscreen, then viewWillAppear: will take care of this
  387. if(self.view.window) {
  388. [self.centerViewController beginAppearanceTransition:YES animated:NO];
  389. [self.centerViewController endAppearanceTransition];
  390. }
  391. [self.centerViewController didMoveToParentViewController:self];
  392. }
  393. }
  394. -(void)setCenterViewController:(UIViewController *)newCenterViewController withCloseAnimation:(BOOL)animated completion:(void(^)(BOOL finished))completion{
  395. if(self.openSide == MMDrawerSideNone){
  396. //If a side drawer isn't open, there is nothing to animate...
  397. animated = NO;
  398. }
  399. BOOL forwardAppearanceMethodsToCenterViewController = ([self.centerViewController isEqual:newCenterViewController] == NO);
  400. UIViewController * oldCenterViewController = self.centerViewController;
  401. // This is related to issue 363 (https://github.com/novkostya/MMDrawerController/pull/363)
  402. // This needs to be refactored so the appearance logic is easier
  403. // to follow across the multiple close/setter methods
  404. if (animated && forwardAppearanceMethodsToCenterViewController) {
  405. [oldCenterViewController beginAppearanceTransition:NO animated:NO];
  406. }
  407. [self setCenterViewController:newCenterViewController animated:animated];
  408. // Related to note above.
  409. if (animated && forwardAppearanceMethodsToCenterViewController) {
  410. [oldCenterViewController endAppearanceTransition];
  411. }
  412. if(animated){
  413. [self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:1.0];
  414. if (forwardAppearanceMethodsToCenterViewController) {
  415. [self.centerViewController beginAppearanceTransition:YES animated:animated];
  416. }
  417. [self
  418. closeDrawerAnimated:animated
  419. completion:^(BOOL finished) {
  420. if (forwardAppearanceMethodsToCenterViewController) {
  421. [self.centerViewController endAppearanceTransition];
  422. [self.centerViewController didMoveToParentViewController:self];
  423. }
  424. if(completion){
  425. completion(finished);
  426. }
  427. }];
  428. }
  429. else {
  430. if(completion) {
  431. completion(YES);
  432. }
  433. }
  434. }
  435. -(void)setCenterViewController:(UIViewController *)newCenterViewController withFullCloseAnimation:(BOOL)animated completion:(void(^)(BOOL finished))completion{
  436. if(self.openSide != MMDrawerSideNone &&
  437. animated){
  438. BOOL forwardAppearanceMethodsToCenterViewController = ([self.centerViewController isEqual:newCenterViewController] == NO);
  439. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:self.openSide];
  440. CGFloat targetClosePoint = 0.0f;
  441. if(self.openSide == MMDrawerSideRight){
  442. targetClosePoint = -CGRectGetWidth(self.childControllerContainerView.bounds);
  443. }
  444. else if(self.openSide == MMDrawerSideLeft) {
  445. targetClosePoint = CGRectGetWidth(self.childControllerContainerView.bounds);
  446. }
  447. CGFloat distance = ABS(self.centerContainerView.frame.origin.x-targetClosePoint);
  448. NSTimeInterval firstDuration = [self animationDurationForAnimationDistance:distance];
  449. CGRect newCenterRect = self.centerContainerView.frame;
  450. [self setAnimatingDrawer:animated];
  451. UIViewController * oldCenterViewController = self.centerViewController;
  452. if(forwardAppearanceMethodsToCenterViewController ){
  453. [oldCenterViewController beginAppearanceTransition:NO animated:animated];
  454. }
  455. newCenterRect.origin.x = targetClosePoint;
  456. [UIView
  457. animateWithDuration:firstDuration
  458. delay:0.0
  459. options:UIViewAnimationOptionCurveEaseInOut
  460. animations:^{
  461. [self.centerContainerView setFrame:newCenterRect withLayoutAlpha:1.0];
  462. [sideDrawerViewController.view setFrame:self.childControllerContainerView.bounds];
  463. }
  464. completion:^(BOOL finished) {
  465. CGRect oldCenterRect = self.centerContainerView.frame;
  466. [self setCenterViewController:newCenterViewController animated:animated];
  467. [self.centerContainerView setFrame:oldCenterRect withLayoutAlpha:1.0];
  468. [self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:1.0];
  469. if(forwardAppearanceMethodsToCenterViewController) {
  470. [oldCenterViewController endAppearanceTransition];
  471. [self.centerViewController beginAppearanceTransition:YES animated:animated];
  472. }
  473. [sideDrawerViewController beginAppearanceTransition:NO animated:animated];
  474. [UIView
  475. animateWithDuration:[self animationDurationForAnimationDistance:CGRectGetWidth(self.childControllerContainerView.bounds)]
  476. delay:MMDrawerDefaultFullAnimationDelay
  477. options:UIViewAnimationOptionCurveEaseInOut
  478. animations:^{
  479. [self.centerContainerView setFrame:self.childControllerContainerView.bounds withLayoutAlpha:1.0];
  480. [self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:0.0];
  481. }
  482. completion:^(BOOL finished) {
  483. if (forwardAppearanceMethodsToCenterViewController) {
  484. [self.centerViewController endAppearanceTransition];
  485. [self.centerViewController didMoveToParentViewController:self];
  486. }
  487. [sideDrawerViewController endAppearanceTransition];
  488. [self resetDrawerVisualStateForDrawerSide:self.openSide];
  489. [sideDrawerViewController.view setFrame:sideDrawerViewController.mm_visibleDrawerFrame];
  490. [self setOpenSide:MMDrawerSideNone];
  491. [self setAnimatingDrawer:NO];
  492. if(completion){
  493. completion(finished);
  494. }
  495. }];
  496. }];
  497. }
  498. else {
  499. [self setCenterViewController:newCenterViewController animated:animated];
  500. if(self.openSide != MMDrawerSideNone){
  501. [self closeDrawerAnimated:animated completion:completion];
  502. }
  503. else if(completion){
  504. completion(YES);
  505. }
  506. }
  507. }
  508. -(void)setCenterOverlayColor:(UIColor*)color {
  509. if (color) {
  510. self.centerContainerView.overlayView.backgroundColor = color;
  511. }
  512. }
  513. #pragma mark - Size Methods
  514. -(void)setMaximumLeftDrawerWidth:(CGFloat)width animated:(BOOL)animated completion:(void(^)(BOOL finished))completion{
  515. [self setMaximumDrawerWidth:width forSide:MMDrawerSideLeft animated:animated completion:completion];
  516. }
  517. -(void)setMaximumRightDrawerWidth:(CGFloat)width animated:(BOOL)animated completion:(void(^)(BOOL finished))completion{
  518. [self setMaximumDrawerWidth:width forSide:MMDrawerSideRight animated:animated completion:completion];
  519. }
  520. - (void)setMaximumDrawerWidth:(CGFloat)width forSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void(^)(BOOL finished))completion{
  521. NSParameterAssert(width > 0);
  522. NSParameterAssert(drawerSide != MMDrawerSideNone);
  523. UIViewController *sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  524. CGFloat oldWidth = 0.f;
  525. NSInteger drawerSideOriginCorrection = 1;
  526. if (drawerSide == MMDrawerSideLeft) {
  527. oldWidth = _maximumLeftDrawerWidth;
  528. _maximumLeftDrawerWidth = width;
  529. }
  530. else if(drawerSide == MMDrawerSideRight){
  531. oldWidth = _maximumRightDrawerWidth;
  532. _maximumRightDrawerWidth = width;
  533. drawerSideOriginCorrection = -1;
  534. }
  535. CGFloat distance = ABS(width-oldWidth);
  536. NSTimeInterval duration = [self animationDurationForAnimationDistance:distance];
  537. if(self.openSide == drawerSide){
  538. CGRect newCenterRect = self.centerContainerView.frame;
  539. newCenterRect.origin.x = drawerSideOriginCorrection*width;
  540. [UIView
  541. animateWithDuration:(animated?duration:0)
  542. delay:0.0
  543. options:UIViewAnimationOptionCurveEaseInOut
  544. animations:^{
  545. [self.centerContainerView setFrame:newCenterRect withLayoutAlpha:1.0];
  546. [sideDrawerViewController.view setFrame:sideDrawerViewController.mm_visibleDrawerFrame];
  547. }
  548. completion:^(BOOL finished) {
  549. if(completion != nil){
  550. completion(finished);
  551. }
  552. }];
  553. }
  554. else{
  555. [sideDrawerViewController.view setFrame:sideDrawerViewController.mm_visibleDrawerFrame];
  556. if(completion != nil){
  557. completion(YES);
  558. }
  559. }
  560. }
  561. #pragma mark - Bounce Methods
  562. -(void)bouncePreviewForDrawerSide:(MMDrawerSide)drawerSide completion:(void(^)(BOOL finished))completion{
  563. NSParameterAssert(drawerSide!=MMDrawerSideNone);
  564. [self bouncePreviewForDrawerSide:drawerSide distance:MMDrawerDefaultBounceDistance completion:completion];
  565. }
  566. -(void)bouncePreviewForDrawerSide:(MMDrawerSide)drawerSide distance:(CGFloat)distance completion:(void(^)(BOOL finished))completion{
  567. NSParameterAssert(drawerSide!=MMDrawerSideNone);
  568. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  569. if(sideDrawerViewController == nil ||
  570. self.openSide != MMDrawerSideNone){
  571. if(completion){
  572. completion(NO);
  573. }
  574. return;
  575. }
  576. else {
  577. [self prepareToPresentDrawer:drawerSide animated:YES];
  578. [self updateDrawerVisualStateForDrawerSide:drawerSide percentVisible:1.0];
  579. [CATransaction begin];
  580. [CATransaction
  581. setCompletionBlock:^{
  582. [sideDrawerViewController endAppearanceTransition];
  583. [sideDrawerViewController beginAppearanceTransition:NO animated:NO];
  584. [sideDrawerViewController endAppearanceTransition];
  585. if(completion){
  586. completion(YES);
  587. }
  588. }];
  589. CGFloat modifier = ((drawerSide == MMDrawerSideLeft)?1.0:-1.0);
  590. CAKeyframeAnimation *animation = bounceKeyFrameAnimationForDistanceOnView(distance*modifier,self.centerContainerView);
  591. [self.centerContainerView.layer addAnimation:animation forKey:@"bouncing"];
  592. [CATransaction commit];
  593. }
  594. }
  595. #pragma mark - Setting Drawer Visual State
  596. -(void)setDrawerVisualStateBlock:(void (^)(MMDrawerController *, MMDrawerSide, CGFloat))drawerVisualStateBlock{
  597. [self setDrawerVisualState:drawerVisualStateBlock];
  598. }
  599. #pragma mark - Setting Custom Gesture Handler Block
  600. -(void)setGestureShouldRecognizeTouchBlock:(BOOL (^)(MMDrawerController *, UIGestureRecognizer *, UITouch *))gestureShouldRecognizeTouchBlock{
  601. [self setGestureShouldRecognizeTouch:gestureShouldRecognizeTouchBlock];
  602. }
  603. #pragma mark - Setting the Gesture Completion Block
  604. -(void)setGestureCompletionBlock:(void (^)(MMDrawerController *, UIGestureRecognizer *))gestureCompletionBlock{
  605. [self setGestureCompletion:gestureCompletionBlock];
  606. }
  607. #pragma mark - Setting the Gesture Start Block
  608. -(void)setGestureStartBlock:(void (^)(MMDrawerController *, UIGestureRecognizer *))gestureStartBlock{
  609. [self setGestureStart:gestureStartBlock];
  610. }
  611. #pragma mark - Subclass Methods
  612. -(BOOL)shouldAutomaticallyForwardAppearanceMethods{
  613. return NO;
  614. }
  615. -(BOOL)shouldAutomaticallyForwardRotationMethods{
  616. return NO;
  617. }
  618. -(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers{
  619. return NO;
  620. }
  621. #pragma mark - View Lifecycle
  622. - (void)viewDidLoad {
  623. [super viewDidLoad];
  624. [self.view setBackgroundColor:[UIColor blackColor]];
  625. [self setupGestureRecognizers];
  626. }
  627. -(void)viewWillAppear:(BOOL)animated{
  628. [super viewWillAppear:animated];
  629. [self.centerViewController beginAppearanceTransition:YES animated:animated];
  630. if(self.openSide == MMDrawerSideLeft) {
  631. [self.leftDrawerViewController beginAppearanceTransition:YES animated:animated];
  632. }
  633. else if(self.openSide == MMDrawerSideRight) {
  634. [self.rightDrawerViewController beginAppearanceTransition:YES animated:animated];
  635. }
  636. }
  637. -(void)viewDidAppear:(BOOL)animated{
  638. [super viewDidAppear:animated];
  639. [self updateShadowForCenterView];
  640. [self.centerViewController endAppearanceTransition];
  641. if(self.openSide == MMDrawerSideLeft) {
  642. [self.leftDrawerViewController endAppearanceTransition];
  643. }
  644. else if(self.openSide == MMDrawerSideRight) {
  645. [self.rightDrawerViewController endAppearanceTransition];
  646. }
  647. }
  648. -(void)viewWillDisappear:(BOOL)animated{
  649. [super viewWillDisappear:animated];
  650. [self.centerViewController beginAppearanceTransition:NO animated:animated];
  651. if(self.openSide == MMDrawerSideLeft) {
  652. [self.leftDrawerViewController beginAppearanceTransition:NO animated:animated];
  653. }
  654. else if (self.openSide == MMDrawerSideRight) {
  655. [self.rightDrawerViewController beginAppearanceTransition:NO animated:animated];
  656. }
  657. }
  658. -(void)viewDidDisappear:(BOOL)animated{
  659. [super viewDidDisappear:animated];
  660. [self.centerViewController endAppearanceTransition];
  661. if(self.openSide == MMDrawerSideLeft) {
  662. [self.leftDrawerViewController endAppearanceTransition];
  663. }
  664. else if (self.openSide == MMDrawerSideRight) {
  665. [self.rightDrawerViewController endAppearanceTransition];
  666. }
  667. }
  668. #pragma mark Rotation
  669. -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
  670. [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  671. //If a rotation begins, we are going to cancel the current gesture and reset transform and anchor points so everything works correctly
  672. BOOL gestureInProgress = NO;
  673. for(UIGestureRecognizer * gesture in self.view.gestureRecognizers){
  674. if(gesture.state == UIGestureRecognizerStateChanged){
  675. [gesture setEnabled:NO];
  676. [gesture setEnabled:YES];
  677. gestureInProgress = YES;
  678. }
  679. if (gestureInProgress) {
  680. [self resetDrawerVisualStateForDrawerSide:self.openSide];
  681. }
  682. }
  683. if ([self needsManualForwardingOfRotationEvents]){
  684. for(UIViewController * childViewController in self.childViewControllers){
  685. [childViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  686. }
  687. }
  688. }
  689. -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
  690. [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
  691. //We need to support the shadow path rotation animation
  692. //Inspired from here: http://blog.radi.ws/post/8348898129/calayers-shadowpath-and-uiview-autoresizing
  693. if(self.showsShadow){
  694. CGPathRef oldShadowPath = self.centerContainerView.layer.shadowPath;
  695. if(oldShadowPath){
  696. CFRetain(oldShadowPath);
  697. }
  698. [self updateShadowForCenterView];
  699. if (oldShadowPath) {
  700. [self.centerContainerView.layer addAnimation:((^ {
  701. CABasicAnimation *transition = [CABasicAnimation animationWithKeyPath:@"shadowPath"];
  702. transition.fromValue = (__bridge id)oldShadowPath;
  703. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  704. transition.duration = duration;
  705. return transition;
  706. })()) forKey:@"transition"];
  707. CFRelease(oldShadowPath);
  708. }
  709. }
  710. if ([self needsManualForwardingOfRotationEvents]){
  711. for(UIViewController * childViewController in self.childViewControllers){
  712. [childViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
  713. }
  714. }
  715. }
  716. -(BOOL)shouldAutorotate{
  717. return YES;
  718. }
  719. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
  720. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  721. if ([self needsManualForwardingOfRotationEvents]){
  722. for(UIViewController * childViewController in self.childViewControllers){
  723. [childViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  724. }
  725. }
  726. }
  727. #pragma mark - Setters
  728. -(void)setRightDrawerViewController:(UIViewController *)rightDrawerViewController{
  729. [self setDrawerViewController:rightDrawerViewController forSide:MMDrawerSideRight];
  730. }
  731. -(void)setLeftDrawerViewController:(UIViewController *)leftDrawerViewController{
  732. [self setDrawerViewController:leftDrawerViewController forSide:MMDrawerSideLeft];
  733. }
  734. - (void)setDrawerViewController:(UIViewController *)viewController forSide:(MMDrawerSide)drawerSide{
  735. NSParameterAssert(drawerSide != MMDrawerSideNone);
  736. UIViewController *currentSideViewController = [self sideDrawerViewControllerForSide:drawerSide];
  737. if (currentSideViewController == viewController) {
  738. return;
  739. }
  740. if (currentSideViewController != nil) {
  741. [currentSideViewController beginAppearanceTransition:NO animated:NO];
  742. [currentSideViewController.view removeFromSuperview];
  743. [currentSideViewController endAppearanceTransition];
  744. [currentSideViewController willMoveToParentViewController:nil];
  745. [currentSideViewController removeFromParentViewController];
  746. }
  747. UIViewAutoresizing autoResizingMask = 0;
  748. if (drawerSide == MMDrawerSideLeft) {
  749. _leftDrawerViewController = viewController;
  750. autoResizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
  751. }
  752. else if(drawerSide == MMDrawerSideRight){
  753. _rightDrawerViewController = viewController;
  754. autoResizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
  755. }
  756. if(viewController){
  757. [self addChildViewController:viewController];
  758. if((self.openSide == drawerSide) &&
  759. [self.childControllerContainerView.subviews containsObject:self.centerContainerView]){
  760. [self.childControllerContainerView insertSubview:viewController.view belowSubview:self.centerContainerView];
  761. [viewController beginAppearanceTransition:YES animated:NO];
  762. [viewController endAppearanceTransition];
  763. }
  764. else{
  765. [self.childControllerContainerView addSubview:viewController.view];
  766. [self.childControllerContainerView sendSubviewToBack:viewController.view];
  767. [viewController.view setHidden:YES];
  768. }
  769. [viewController didMoveToParentViewController:self];
  770. [viewController.view setAutoresizingMask:autoResizingMask];
  771. [viewController.view setFrame:viewController.mm_visibleDrawerFrame];
  772. }
  773. }
  774. -(void)setCenterViewController:(UIViewController *)centerViewController{
  775. [self setCenterViewController:centerViewController animated:NO];
  776. }
  777. -(void)setShowsShadow:(BOOL)showsShadow{
  778. _showsShadow = showsShadow;
  779. [self updateShadowForCenterView];
  780. }
  781. - (void)setShadowRadius:(CGFloat)shadowRadius{
  782. _shadowRadius = shadowRadius;
  783. [self updateShadowForCenterView];
  784. }
  785. - (void)setShadowOpacity:(CGFloat)shadowOpacity{
  786. _shadowOpacity = shadowOpacity;
  787. [self updateShadowForCenterView];
  788. }
  789. - (void)setShadowOffset:(CGSize)shadowOffset{
  790. _shadowOffset = shadowOffset;
  791. [self updateShadowForCenterView];
  792. }
  793. - (void)setShadowColor:(UIColor *)shadowColor{
  794. _shadowColor = shadowColor;
  795. [self updateShadowForCenterView];
  796. }
  797. -(void)setOpenSide:(MMDrawerSide)openSide{
  798. if(_openSide != openSide){
  799. _openSide = openSide;
  800. [self.centerContainerView setOpenSide:openSide];
  801. if(openSide == MMDrawerSideNone){
  802. [self.leftDrawerViewController.view setHidden:YES];
  803. [self.rightDrawerViewController.view setHidden:YES];
  804. }
  805. [self setNeedsStatusBarAppearanceUpdateIfSupported];
  806. }
  807. }
  808. -(void)setCenterHiddenInteractionMode:(MMDrawerOpenCenterInteractionMode)centerHiddenInteractionMode{
  809. if(_centerHiddenInteractionMode!=centerHiddenInteractionMode){
  810. _centerHiddenInteractionMode = centerHiddenInteractionMode;
  811. [self.centerContainerView setCenterInteractionMode:centerHiddenInteractionMode];
  812. }
  813. }
  814. -(void)setMaximumLeftDrawerWidth:(CGFloat)maximumLeftDrawerWidth{
  815. [self setMaximumLeftDrawerWidth:maximumLeftDrawerWidth animated:NO completion:nil];
  816. }
  817. -(void)setMaximumRightDrawerWidth:(CGFloat)maximumRightDrawerWidth{
  818. [self setMaximumRightDrawerWidth:maximumRightDrawerWidth animated:NO completion:nil];
  819. }
  820. -(void)setShowsStatusBarBackgroundView:(BOOL)showsDummyStatusBar{
  821. if(showsDummyStatusBar!=_showsStatusBarBackgroundView){
  822. _showsStatusBarBackgroundView = showsDummyStatusBar;
  823. CGRect frame = self.childControllerContainerView.frame;
  824. if(_showsStatusBarBackgroundView){
  825. frame.origin.y = 20;
  826. frame.size.height = CGRectGetHeight(self.view.bounds)-20;
  827. }
  828. else {
  829. frame.origin.y = 0;
  830. frame.size.height = CGRectGetHeight(self.view.bounds);
  831. }
  832. [self.childControllerContainerView setFrame:frame];
  833. [self.dummyStatusBarView setHidden:!showsDummyStatusBar];
  834. }
  835. }
  836. -(void)setStatusBarViewBackgroundColor:(UIColor *)dummyStatusBarColor{
  837. _statusBarViewBackgroundColor = dummyStatusBarColor;
  838. [self.dummyStatusBarView setBackgroundColor:_statusBarViewBackgroundColor];
  839. }
  840. -(void)setAnimatingDrawer:(BOOL)animatingDrawer{
  841. _animatingDrawer = animatingDrawer;
  842. [self.view setUserInteractionEnabled:!animatingDrawer];
  843. }
  844. #pragma mark - Getters
  845. -(CGFloat)maximumLeftDrawerWidth{
  846. if(self.leftDrawerViewController){
  847. return _maximumLeftDrawerWidth;
  848. }
  849. else{
  850. return 0;
  851. }
  852. }
  853. -(CGFloat)maximumRightDrawerWidth{
  854. if(self.rightDrawerViewController){
  855. return _maximumRightDrawerWidth;
  856. }
  857. else {
  858. return 0;
  859. }
  860. }
  861. -(CGFloat)visibleLeftDrawerWidth{
  862. return MAX(0.0,CGRectGetMinX(self.centerContainerView.frame));
  863. }
  864. -(CGFloat)visibleRightDrawerWidth{
  865. if(CGRectGetMinX(self.centerContainerView.frame)<0){
  866. return CGRectGetWidth(self.childControllerContainerView.bounds)-CGRectGetMaxX(self.centerContainerView.frame);
  867. }
  868. else {
  869. return 0.0f;
  870. }
  871. }
  872. -(UIView*)childControllerContainerView{
  873. if(_childControllerContainerView == nil){
  874. //Issue #152 (https://github.com/mutualmobile/MMDrawerController/issues/152)
  875. //Turns out we have two child container views getting added to the view during init,
  876. //because the first request self.view.bounds was kicking off a viewDidLoad, which
  877. //caused us to be able to fall through this check twice.
  878. //
  879. //The fix is to grab the bounds, and then check again that the child container view has
  880. //not been created.
  881. CGRect childContainerViewFrame = self.view.bounds;
  882. if(_childControllerContainerView == nil){
  883. _childControllerContainerView = [[UIView alloc] initWithFrame:childContainerViewFrame];
  884. [_childControllerContainerView setBackgroundColor:[UIColor clearColor]];
  885. [_childControllerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
  886. [self.view addSubview:_childControllerContainerView];
  887. }
  888. }
  889. return _childControllerContainerView;
  890. }
  891. -(UIView*)dummyStatusBarView{
  892. if(_dummyStatusBarView==nil){
  893. _dummyStatusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 20)];
  894. [_dummyStatusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
  895. [_dummyStatusBarView setBackgroundColor:self.statusBarViewBackgroundColor];
  896. [_dummyStatusBarView setHidden:!_showsStatusBarBackgroundView];
  897. [self.view addSubview:_dummyStatusBarView];
  898. }
  899. return _dummyStatusBarView;
  900. }
  901. -(UIColor*)statusBarViewBackgroundColor{
  902. if(_statusBarViewBackgroundColor == nil){
  903. _statusBarViewBackgroundColor = [UIColor blackColor];
  904. }
  905. return _statusBarViewBackgroundColor;
  906. }
  907. #pragma mark - Gesture Handlers
  908. -(void)tapGestureCallback:(UITapGestureRecognizer *)tapGesture{
  909. if(self.openSide != MMDrawerSideNone &&
  910. self.isAnimatingDrawer == NO){
  911. [self closeDrawerAnimated:YES completion:^(BOOL finished) {
  912. if(self.gestureCompletion){
  913. self.gestureCompletion(self, tapGesture);
  914. }
  915. }];
  916. }
  917. }
  918. -(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture{
  919. switch (panGesture.state) {
  920. case UIGestureRecognizerStateBegan:{
  921. if(self.gestureStart){
  922. self.gestureStart(self, panGesture);
  923. }
  924. if(self.animatingDrawer){
  925. [panGesture setEnabled:NO];
  926. break;
  927. }
  928. else {
  929. self.startingPanRect = self.centerContainerView.frame;
  930. }
  931. }
  932. case UIGestureRecognizerStateChanged:{
  933. self.view.userInteractionEnabled = NO;
  934. CGRect newFrame = self.startingPanRect;
  935. CGPoint translatedPoint = [panGesture translationInView:self.centerContainerView];
  936. newFrame.origin.x = [self roundedOriginXForDrawerConstriants:CGRectGetMinX(self.startingPanRect)+translatedPoint.x];
  937. newFrame = CGRectIntegral(newFrame);
  938. CGFloat xOffset = newFrame.origin.x;
  939. MMDrawerSide visibleSide = MMDrawerSideNone;
  940. CGFloat percentVisible = 0.0;
  941. if(xOffset > 0){
  942. visibleSide = MMDrawerSideLeft;
  943. percentVisible = xOffset/self.maximumLeftDrawerWidth;
  944. }
  945. else if(xOffset < 0){
  946. visibleSide = MMDrawerSideRight;
  947. percentVisible = ABS(xOffset)/self.maximumRightDrawerWidth;
  948. }
  949. if ((!_leftSideEnabled && visibleSide == MMDrawerSideLeft) || (!_rightSideEnabled && visibleSide == MMDrawerSideRight)) {
  950. return;
  951. }
  952. UIViewController * visibleSideDrawerViewController = [self sideDrawerViewControllerForSide:visibleSide];
  953. if(self.openSide != visibleSide){
  954. //Handle disappearing the visible drawer
  955. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:self.openSide];
  956. [sideDrawerViewController beginAppearanceTransition:NO animated:NO];
  957. [sideDrawerViewController endAppearanceTransition];
  958. //Drawer is about to become visible
  959. [self prepareToPresentDrawer:visibleSide animated:NO];
  960. [visibleSideDrawerViewController endAppearanceTransition];
  961. [self setOpenSide:visibleSide];
  962. }
  963. else if(visibleSide == MMDrawerSideNone){
  964. [self setOpenSide:MMDrawerSideNone];
  965. }
  966. [self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:percentVisible];
  967. [self.centerContainerView setCenter:CGPointMake(CGRectGetMidX(newFrame), CGRectGetMidY(newFrame))];
  968. newFrame = self.centerContainerView.frame;
  969. newFrame.origin.x = floor(newFrame.origin.x);
  970. newFrame.origin.y = floor(newFrame.origin.y);
  971. self.centerContainerView.frame = newFrame;
  972. [self.centerContainerView addSubview:self.centerContainerView.overlayView];
  973. [self.centerContainerView bringSubviewToFront:self.centerContainerView.overlayView];
  974. self.centerContainerView.overlayView.alpha = percentVisible;
  975. break;
  976. }
  977. case UIGestureRecognizerStateEnded:
  978. case UIGestureRecognizerStateCancelled: {
  979. self.startingPanRect = CGRectNull;
  980. CGPoint velocity = [panGesture velocityInView:self.childControllerContainerView];
  981. [self finishAnimationForPanGestureWithXVelocity:velocity.x completion:^(BOOL finished) {
  982. if(self.gestureCompletion){
  983. self.gestureCompletion(self, panGesture);
  984. }
  985. }];
  986. self.view.userInteractionEnabled = YES;
  987. break;
  988. }
  989. default:
  990. break;
  991. }
  992. }
  993. #pragma mark - iOS 7 Status Bar Helpers
  994. -(UIViewController*)childViewControllerForStatusBarStyle{
  995. return [self childViewControllerForSide:self.openSide];
  996. }
  997. -(UIViewController*)childViewControllerForStatusBarHidden{
  998. return [self childViewControllerForSide:self.openSide];
  999. }
  1000. -(void)setNeedsStatusBarAppearanceUpdateIfSupported{
  1001. if([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
  1002. [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
  1003. }
  1004. }
  1005. #pragma mark - iOS 8 Rotation Helpers
  1006. - (BOOL)needsManualForwardingOfRotationEvents{
  1007. BOOL isIOS8 = (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1);
  1008. return !isIOS8;
  1009. }
  1010. #pragma mark - Animation helpers
  1011. -(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:(void(^)(BOOL finished))completion{
  1012. CGFloat currentOriginX = CGRectGetMinX(self.centerContainerView.frame);
  1013. CGFloat animationVelocity = MAX(ABS(xVelocity),self.panVelocityXAnimationThreshold*2);
  1014. if(self.openSide == MMDrawerSideLeft) {
  1015. CGFloat midPoint = self.maximumLeftDrawerWidth / 2.0;
  1016. if(xVelocity > self.panVelocityXAnimationThreshold){
  1017. [self openDrawerSide:MMDrawerSideLeft animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1018. }
  1019. else if(xVelocity < -self.panVelocityXAnimationThreshold){
  1020. [self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1021. }
  1022. else if(currentOriginX < midPoint){
  1023. [self closeDrawerAnimated:YES completion:completion];
  1024. }
  1025. else {
  1026. [self openDrawerSide:MMDrawerSideLeft animated:YES completion:completion];
  1027. }
  1028. }
  1029. else if(self.openSide == MMDrawerSideRight){
  1030. currentOriginX = CGRectGetMaxX(self.centerContainerView.frame);
  1031. CGFloat midPoint = (CGRectGetWidth(self.childControllerContainerView.bounds)-self.maximumRightDrawerWidth) + (self.maximumRightDrawerWidth / 2.0);
  1032. if(xVelocity > self.panVelocityXAnimationThreshold){
  1033. [self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1034. }
  1035. else if (xVelocity < -self.panVelocityXAnimationThreshold){
  1036. [self openDrawerSide:MMDrawerSideRight animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1037. }
  1038. else if(currentOriginX > midPoint){
  1039. [self closeDrawerAnimated:YES completion:completion];
  1040. }
  1041. else {
  1042. [self openDrawerSide:MMDrawerSideRight animated:YES completion:completion];
  1043. }
  1044. }
  1045. else {
  1046. if(completion){
  1047. completion(NO);
  1048. }
  1049. }
  1050. }
  1051. -(void)updateDrawerVisualStateForDrawerSide:(MMDrawerSide)drawerSide percentVisible:(CGFloat)percentVisible{
  1052. if(self.drawerVisualState){
  1053. self.drawerVisualState(self,drawerSide,percentVisible);
  1054. }
  1055. else if(self.shouldStretchDrawer){
  1056. [self applyOvershootScaleTransformForDrawerSide:drawerSide percentVisible:percentVisible];
  1057. }
  1058. }
  1059. - (void)applyOvershootScaleTransformForDrawerSide:(MMDrawerSide)drawerSide percentVisible:(CGFloat)percentVisible{
  1060. if (percentVisible >= 1.f) {
  1061. CATransform3D transform = CATransform3DIdentity;
  1062. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  1063. if(drawerSide == MMDrawerSideLeft) {
  1064. transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f);
  1065. transform = CATransform3DTranslate(transform, self.maximumLeftDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f);
  1066. }
  1067. else if(drawerSide == MMDrawerSideRight){
  1068. transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f);
  1069. transform = CATransform3DTranslate(transform, -self.maximumRightDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f);
  1070. }
  1071. sideDrawerViewController.view.layer.transform = transform;
  1072. }
  1073. }
  1074. -(void)resetDrawerVisualStateForDrawerSide:(MMDrawerSide)drawerSide{
  1075. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  1076. [sideDrawerViewController.view.layer setAnchorPoint:CGPointMake(0.5f, 0.5f)];
  1077. [sideDrawerViewController.view.layer setTransform:CATransform3DIdentity];
  1078. [sideDrawerViewController.view setAlpha:1.0];
  1079. }
  1080. -(CGFloat)roundedOriginXForDrawerConstriants:(CGFloat)originX{
  1081. if (originX < -self.maximumRightDrawerWidth) {
  1082. if (self.shouldStretchDrawer &&
  1083. self.rightDrawerViewController) {
  1084. CGFloat maxOvershoot = (CGRectGetWidth(self.centerContainerView.frame)-self.maximumRightDrawerWidth)*MMDrawerOvershootPercentage;
  1085. return originXForDrawerOriginAndTargetOriginOffset(originX, -self.maximumRightDrawerWidth, maxOvershoot);
  1086. }
  1087. else{
  1088. return -self.maximumRightDrawerWidth;
  1089. }
  1090. }
  1091. else if(originX > self.maximumLeftDrawerWidth){
  1092. if (self.shouldStretchDrawer &&
  1093. self.leftDrawerViewController) {
  1094. CGFloat maxOvershoot = (CGRectGetWidth(self.centerContainerView.frame)-self.maximumLeftDrawerWidth)*MMDrawerOvershootPercentage;
  1095. return originXForDrawerOriginAndTargetOriginOffset(originX, self.maximumLeftDrawerWidth, maxOvershoot);
  1096. }
  1097. else{
  1098. return self.maximumLeftDrawerWidth;
  1099. }
  1100. }
  1101. return originX;
  1102. }
  1103. static inline CGFloat originXForDrawerOriginAndTargetOriginOffset(CGFloat originX, CGFloat targetOffset, CGFloat maxOvershoot){
  1104. CGFloat delta = ABS(originX - targetOffset);
  1105. CGFloat maxLinearPercentage = MMDrawerOvershootLinearRangePercentage;
  1106. CGFloat nonLinearRange = maxOvershoot * maxLinearPercentage;
  1107. CGFloat nonLinearScalingDelta = (delta - nonLinearRange);
  1108. CGFloat overshoot = nonLinearRange + nonLinearScalingDelta * nonLinearRange/sqrt(pow(nonLinearScalingDelta,2.f) + 15000);
  1109. if (delta < nonLinearRange) {
  1110. return originX;
  1111. }
  1112. else if (targetOffset < 0) {
  1113. return targetOffset - round(overshoot);
  1114. }
  1115. else{
  1116. return targetOffset + round(overshoot);
  1117. }
  1118. }
  1119. #pragma mark - Helpers
  1120. -(void)setupGestureRecognizers{
  1121. UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];
  1122. [pan setDelegate:self];
  1123. [self.view addGestureRecognizer:pan];
  1124. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];
  1125. [tap setDelegate:self];
  1126. [self.view addGestureRecognizer:tap];
  1127. }
  1128. -(void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated{
  1129. MMDrawerSide drawerToHide = MMDrawerSideNone;
  1130. if(drawer == MMDrawerSideLeft){
  1131. drawerToHide = MMDrawerSideRight;
  1132. }
  1133. else if(drawer == MMDrawerSideRight){
  1134. drawerToHide = MMDrawerSideLeft;
  1135. }
  1136. UIViewController * sideDrawerViewControllerToPresent = [self sideDrawerViewControllerForSide:drawer];
  1137. UIViewController * sideDrawerViewControllerToHide = [self sideDrawerViewControllerForSide:drawerToHide];
  1138. [self.childControllerContainerView sendSubviewToBack:sideDrawerViewControllerToHide.view];
  1139. [sideDrawerViewControllerToHide.view setHidden:YES];
  1140. [sideDrawerViewControllerToPresent.view setHidden:NO];
  1141. [self resetDrawerVisualStateForDrawerSide:drawer];
  1142. [sideDrawerViewControllerToPresent.view setFrame:sideDrawerViewControllerToPresent.mm_visibleDrawerFrame];
  1143. [self updateDrawerVisualStateForDrawerSide:drawer percentVisible:0.0];
  1144. [sideDrawerViewControllerToPresent beginAppearanceTransition:YES animated:animated];
  1145. }
  1146. -(void)updateShadowForCenterView{
  1147. UIView * centerView = self.centerContainerView;
  1148. if(self.showsShadow){
  1149. centerView.layer.masksToBounds = NO;
  1150. centerView.layer.shadowRadius = self.shadowRadius;
  1151. centerView.layer.shadowOpacity = self.shadowOpacity;
  1152. centerView.layer.shadowOffset = self.shadowOffset;
  1153. centerView.layer.shadowColor = [self.shadowColor CGColor];
  1154. /** In the event this gets called a lot, we won't update the shadowPath
  1155. unless it needs to be updated (like during rotation) */
  1156. if (centerView.layer.shadowPath == NULL) {
  1157. centerView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:self.centerContainerView.bounds] CGPath];
  1158. }
  1159. else{
  1160. CGRect currentPath = CGPathGetPathBoundingBox(centerView.layer.shadowPath);
  1161. if (CGRectEqualToRect(currentPath, centerView.bounds) == NO){
  1162. centerView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:self.centerContainerView.bounds] CGPath];
  1163. }
  1164. }
  1165. }
  1166. else if (centerView.layer.shadowPath != NULL) {
  1167. centerView.layer.shadowRadius = 0.f;
  1168. centerView.layer.shadowOpacity = 0.f;
  1169. centerView.layer.shadowOffset = CGSizeMake(0, -3);
  1170. centerView.layer.shadowPath = NULL;
  1171. centerView.layer.masksToBounds = YES;
  1172. }
  1173. }
  1174. -(NSTimeInterval)animationDurationForAnimationDistance:(CGFloat)distance{
  1175. NSTimeInterval duration = MAX(distance/self.animationVelocity,MMDrawerMinimumAnimationDuration);
  1176. return duration;
  1177. }
  1178. -(UIViewController*)sideDrawerViewControllerForSide:(MMDrawerSide)drawerSide{
  1179. UIViewController * sideDrawerViewController = nil;
  1180. if(drawerSide != MMDrawerSideNone){
  1181. sideDrawerViewController = [self childViewControllerForSide:drawerSide];
  1182. }
  1183. return sideDrawerViewController;
  1184. }
  1185. -(UIViewController*)childViewControllerForSide:(MMDrawerSide)drawerSide{
  1186. UIViewController * childViewController = nil;
  1187. switch (drawerSide) {
  1188. case MMDrawerSideLeft:
  1189. childViewController = self.leftDrawerViewController;
  1190. break;
  1191. case MMDrawerSideRight:
  1192. childViewController = self.rightDrawerViewController;
  1193. break;
  1194. case MMDrawerSideNone:
  1195. childViewController = self.centerViewController;
  1196. break;
  1197. }
  1198. return childViewController;
  1199. }
  1200. #pragma mark - UIGestureRecognizerDelegate
  1201. -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
  1202. if(self.openSide == MMDrawerSideNone){
  1203. MMOpenDrawerGestureMode possibleOpenGestureModes = [self possibleOpenGestureModesForGestureRecognizer:gestureRecognizer
  1204. withTouch:touch];
  1205. return ((self.openDrawerGestureModeMask & possibleOpenGestureModes)>0);
  1206. }
  1207. else{
  1208. MMCloseDrawerGestureMode possibleCloseGestureModes = [self possibleCloseGestureModesForGestureRecognizer:gestureRecognizer
  1209. withTouch:touch];
  1210. return ((self.closeDrawerGestureModeMask & possibleCloseGestureModes)>0);
  1211. }
  1212. }
  1213. #pragma mark Gesture Recogizner Delegate Helpers
  1214. -(MMCloseDrawerGestureMode)possibleCloseGestureModesForGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer withTouch:(UITouch*)touch{
  1215. CGPoint point = [touch locationInView:self.childControllerContainerView];
  1216. MMCloseDrawerGestureMode possibleCloseGestureModes = MMCloseDrawerGestureModeNone;
  1217. if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]){
  1218. if([self isPointContainedWithinNavigationRect:point]){
  1219. possibleCloseGestureModes |= MMCloseDrawerGestureModeTapNavigationBar;
  1220. }
  1221. if([self isPointContainedWithinCenterViewContentRect:point]){
  1222. possibleCloseGestureModes |= MMCloseDrawerGestureModeTapCenterView;
  1223. }
  1224. }
  1225. else if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
  1226. if([self isPointContainedWithinNavigationRect:point]){
  1227. possibleCloseGestureModes |= MMCloseDrawerGestureModePanningNavigationBar;
  1228. }
  1229. if([self isPointContainedWithinCenterViewContentRect:point]){
  1230. possibleCloseGestureModes |= MMCloseDrawerGestureModePanningCenterView;
  1231. }
  1232. if([self isPointContainedWithinRightBezelRect:point] &&
  1233. self.openSide == MMDrawerSideLeft){
  1234. possibleCloseGestureModes |= MMCloseDrawerGestureModeBezelPanningCenterView;
  1235. }
  1236. if([self isPointContainedWithinLeftBezelRect:point] &&
  1237. self.openSide == MMDrawerSideRight){
  1238. possibleCloseGestureModes |= MMCloseDrawerGestureModeBezelPanningCenterView;
  1239. }
  1240. if([self isPointContainedWithinCenterViewContentRect:point] == NO &&
  1241. [self isPointContainedWithinNavigationRect:point] == NO){
  1242. possibleCloseGestureModes |= MMCloseDrawerGestureModePanningDrawerView;
  1243. }
  1244. }
  1245. if((self.closeDrawerGestureModeMask & MMCloseDrawerGestureModeCustom) > 0 &&
  1246. self.gestureShouldRecognizeTouch){
  1247. if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
  1248. possibleCloseGestureModes |= MMCloseDrawerGestureModeCustom;
  1249. }
  1250. }
  1251. return possibleCloseGestureModes;
  1252. }
  1253. -(MMOpenDrawerGestureMode)possibleOpenGestureModesForGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer withTouch:(UITouch*)touch{
  1254. CGPoint point = [touch locationInView:self.childControllerContainerView];
  1255. MMOpenDrawerGestureMode possibleOpenGestureModes = MMOpenDrawerGestureModeNone;
  1256. if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
  1257. if([self isPointContainedWithinNavigationRect:point]){
  1258. possibleOpenGestureModes |= MMOpenDrawerGestureModePanningNavigationBar;
  1259. }
  1260. if([self isPointContainedWithinCenterViewContentRect:point]){
  1261. possibleOpenGestureModes |= MMOpenDrawerGestureModePanningCenterView;
  1262. }
  1263. if([self isPointContainedWithinLeftBezelRect:point] &&
  1264. self.leftDrawerViewController){
  1265. possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
  1266. }
  1267. if([self isPointContainedWithinRightBezelRect:point] &&
  1268. self.rightDrawerViewController){
  1269. possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
  1270. }
  1271. }
  1272. if((self.openDrawerGestureModeMask & MMOpenDrawerGestureModeCustom) > 0 &&
  1273. self.gestureShouldRecognizeTouch){
  1274. if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
  1275. possibleOpenGestureModes |= MMOpenDrawerGestureModeCustom;
  1276. }
  1277. }
  1278. return possibleOpenGestureModes;
  1279. }
  1280. -(BOOL)isPointContainedWithinNavigationRect:(CGPoint)point{
  1281. CGRect navigationBarRect = CGRectNull;
  1282. if([self.centerViewController isKindOfClass:[UINavigationController class]]){
  1283. UINavigationBar * navBar = [(UINavigationController*)self.centerViewController navigationBar];
  1284. navigationBarRect = [navBar convertRect:navBar.bounds toView:self.childControllerContainerView];
  1285. navigationBarRect = CGRectIntersection(navigationBarRect,self.childControllerContainerView.bounds);
  1286. }
  1287. return CGRectContainsPoint(navigationBarRect,point);
  1288. }
  1289. -(BOOL)isPointContainedWithinCenterViewContentRect:(CGPoint)point{
  1290. CGRect centerViewContentRect = self.centerContainerView.frame;
  1291. centerViewContentRect = CGRectIntersection(centerViewContentRect,self.childControllerContainerView.bounds);
  1292. return (CGRectContainsPoint(centerViewContentRect, point) &&
  1293. [self isPointContainedWithinNavigationRect:point] == NO);
  1294. }
  1295. -(BOOL)isPointContainedWithinLeftBezelRect:(CGPoint)point{
  1296. CGRect leftBezelRect = CGRectNull;
  1297. CGRect tempRect;
  1298. CGRectDivide(self.childControllerContainerView.bounds, &leftBezelRect, &tempRect, self.bezelPanningCenterViewRange, CGRectMinXEdge);
  1299. return (CGRectContainsPoint(leftBezelRect, point) &&
  1300. [self isPointContainedWithinCenterViewContentRect:point]);
  1301. }
  1302. -(BOOL)isPointContainedWithinRightBezelRect:(CGPoint)point{
  1303. CGRect rightBezelRect = CGRectNull;
  1304. CGRect tempRect;
  1305. CGRectDivide(self.childControllerContainerView.bounds, &rightBezelRect, &tempRect, self.bezelPanningCenterViewRange, CGRectMaxXEdge);
  1306. return (CGRectContainsPoint(rightBezelRect, point) &&
  1307. [self isPointContainedWithinCenterViewContentRect:point]);
  1308. }
  1309. @end