react-native-navigation的迁移库

MMDrawerController.m 63KB

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