react-native-navigation的迁移库

MMDrawerController.m 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  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. }
  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. if ((!_leftSideEnabled && visibleSide == MMDrawerSideLeft) || (!_rightSideEnabled && visibleSide == MMDrawerSideRight)) {
  949. return;
  950. }
  951. UIViewController * visibleSideDrawerViewController = [self sideDrawerViewControllerForSide:visibleSide];
  952. if(self.openSide != visibleSide){
  953. //Handle disappearing the visible drawer
  954. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:self.openSide];
  955. [sideDrawerViewController beginAppearanceTransition:NO animated:NO];
  956. [sideDrawerViewController endAppearanceTransition];
  957. //Drawer is about to become visible
  958. [self prepareToPresentDrawer:visibleSide animated:NO];
  959. [visibleSideDrawerViewController endAppearanceTransition];
  960. [self setOpenSide:visibleSide];
  961. }
  962. else if(visibleSide == MMDrawerSideNone){
  963. [self setOpenSide:MMDrawerSideNone];
  964. }
  965. [self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:percentVisible];
  966. [self.centerContainerView setCenter:CGPointMake(CGRectGetMidX(newFrame), CGRectGetMidY(newFrame))];
  967. newFrame = self.centerContainerView.frame;
  968. newFrame.origin.x = floor(newFrame.origin.x);
  969. newFrame.origin.y = floor(newFrame.origin.y);
  970. self.centerContainerView.frame = newFrame;
  971. [self.centerContainerView addSubview:self.centerContainerView.overlayView];
  972. [self.centerContainerView bringSubviewToFront:self.centerContainerView.overlayView];
  973. self.centerContainerView.overlayView.alpha = percentVisible;
  974. break;
  975. }
  976. case UIGestureRecognizerStateEnded:
  977. case UIGestureRecognizerStateCancelled: {
  978. self.startingPanRect = CGRectNull;
  979. CGPoint velocity = [panGesture velocityInView:self.childControllerContainerView];
  980. [self finishAnimationForPanGestureWithXVelocity:velocity.x completion:^(BOOL finished) {
  981. if(self.gestureCompletion){
  982. self.gestureCompletion(self, panGesture);
  983. }
  984. }];
  985. self.view.userInteractionEnabled = YES;
  986. break;
  987. }
  988. default:
  989. break;
  990. }
  991. }
  992. #pragma mark - iOS 7 Status Bar Helpers
  993. -(UIViewController*)childViewControllerForStatusBarStyle{
  994. return [self childViewControllerForSide:self.openSide];
  995. }
  996. -(UIViewController*)childViewControllerForStatusBarHidden{
  997. return [self childViewControllerForSide:self.openSide];
  998. }
  999. -(void)setNeedsStatusBarAppearanceUpdateIfSupported{
  1000. if([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
  1001. [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
  1002. }
  1003. }
  1004. #pragma mark - iOS 8 Rotation Helpers
  1005. - (BOOL)needsManualForwardingOfRotationEvents{
  1006. BOOL isIOS8 = (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1);
  1007. return !isIOS8;
  1008. }
  1009. #pragma mark - Animation helpers
  1010. -(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:(void(^)(BOOL finished))completion{
  1011. CGFloat currentOriginX = CGRectGetMinX(self.centerContainerView.frame);
  1012. CGFloat animationVelocity = MAX(ABS(xVelocity),self.panVelocityXAnimationThreshold*2);
  1013. if(self.openSide == MMDrawerSideLeft) {
  1014. CGFloat midPoint = self.maximumLeftDrawerWidth / 2.0;
  1015. if(xVelocity > self.panVelocityXAnimationThreshold){
  1016. [self openDrawerSide:MMDrawerSideLeft animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1017. }
  1018. else if(xVelocity < -self.panVelocityXAnimationThreshold){
  1019. [self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1020. }
  1021. else if(currentOriginX < midPoint){
  1022. [self closeDrawerAnimated:YES completion:completion];
  1023. }
  1024. else {
  1025. [self openDrawerSide:MMDrawerSideLeft animated:YES completion:completion];
  1026. }
  1027. }
  1028. else if(self.openSide == MMDrawerSideRight){
  1029. currentOriginX = CGRectGetMaxX(self.centerContainerView.frame);
  1030. CGFloat midPoint = (CGRectGetWidth(self.childControllerContainerView.bounds)-self.maximumRightDrawerWidth) + (self.maximumRightDrawerWidth / 2.0);
  1031. if(xVelocity > self.panVelocityXAnimationThreshold){
  1032. [self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1033. }
  1034. else if (xVelocity < -self.panVelocityXAnimationThreshold){
  1035. [self openDrawerSide:MMDrawerSideRight animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
  1036. }
  1037. else if(currentOriginX > midPoint){
  1038. [self closeDrawerAnimated:YES completion:completion];
  1039. }
  1040. else {
  1041. [self openDrawerSide:MMDrawerSideRight animated:YES completion:completion];
  1042. }
  1043. }
  1044. else {
  1045. if(completion){
  1046. completion(NO);
  1047. }
  1048. }
  1049. }
  1050. -(void)updateDrawerVisualStateForDrawerSide:(MMDrawerSide)drawerSide percentVisible:(CGFloat)percentVisible{
  1051. if(self.drawerVisualState){
  1052. self.drawerVisualState(self,drawerSide,percentVisible);
  1053. }
  1054. else if(self.shouldStretchDrawer){
  1055. [self applyOvershootScaleTransformForDrawerSide:drawerSide percentVisible:percentVisible];
  1056. }
  1057. }
  1058. - (void)applyOvershootScaleTransformForDrawerSide:(MMDrawerSide)drawerSide percentVisible:(CGFloat)percentVisible{
  1059. if (percentVisible >= 1.f) {
  1060. CATransform3D transform = CATransform3DIdentity;
  1061. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  1062. if(drawerSide == MMDrawerSideLeft) {
  1063. transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f);
  1064. transform = CATransform3DTranslate(transform, self.maximumLeftDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f);
  1065. }
  1066. else if(drawerSide == MMDrawerSideRight){
  1067. transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f);
  1068. transform = CATransform3DTranslate(transform, -self.maximumRightDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f);
  1069. }
  1070. sideDrawerViewController.view.layer.transform = transform;
  1071. }
  1072. }
  1073. -(void)resetDrawerVisualStateForDrawerSide:(MMDrawerSide)drawerSide{
  1074. UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide];
  1075. [sideDrawerViewController.view.layer setAnchorPoint:CGPointMake(0.5f, 0.5f)];
  1076. [sideDrawerViewController.view.layer setTransform:CATransform3DIdentity];
  1077. [sideDrawerViewController.view setAlpha:1.0];
  1078. }
  1079. -(CGFloat)roundedOriginXForDrawerConstriants:(CGFloat)originX{
  1080. if (originX < -self.maximumRightDrawerWidth) {
  1081. if (self.shouldStretchDrawer &&
  1082. self.rightDrawerViewController) {
  1083. CGFloat maxOvershoot = (CGRectGetWidth(self.centerContainerView.frame)-self.maximumRightDrawerWidth)*MMDrawerOvershootPercentage;
  1084. return originXForDrawerOriginAndTargetOriginOffset(originX, -self.maximumRightDrawerWidth, maxOvershoot);
  1085. }
  1086. else{
  1087. return -self.maximumRightDrawerWidth;
  1088. }
  1089. }
  1090. else if(originX > self.maximumLeftDrawerWidth){
  1091. if (self.shouldStretchDrawer &&
  1092. self.leftDrawerViewController) {
  1093. CGFloat maxOvershoot = (CGRectGetWidth(self.centerContainerView.frame)-self.maximumLeftDrawerWidth)*MMDrawerOvershootPercentage;
  1094. return originXForDrawerOriginAndTargetOriginOffset(originX, self.maximumLeftDrawerWidth, maxOvershoot);
  1095. }
  1096. else{
  1097. return self.maximumLeftDrawerWidth;
  1098. }
  1099. }
  1100. return originX;
  1101. }
  1102. static inline CGFloat originXForDrawerOriginAndTargetOriginOffset(CGFloat originX, CGFloat targetOffset, CGFloat maxOvershoot){
  1103. CGFloat delta = ABS(originX - targetOffset);
  1104. CGFloat maxLinearPercentage = MMDrawerOvershootLinearRangePercentage;
  1105. CGFloat nonLinearRange = maxOvershoot * maxLinearPercentage;
  1106. CGFloat nonLinearScalingDelta = (delta - nonLinearRange);
  1107. CGFloat overshoot = nonLinearRange + nonLinearScalingDelta * nonLinearRange/sqrt(pow(nonLinearScalingDelta,2.f) + 15000);
  1108. if (delta < nonLinearRange) {
  1109. return originX;
  1110. }
  1111. else if (targetOffset < 0) {
  1112. return targetOffset - round(overshoot);
  1113. }
  1114. else{
  1115. return targetOffset + round(overshoot);
  1116. }
  1117. }
  1118. #pragma mark - Helpers
  1119. -(void)setupGestureRecognizers{
  1120. UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];
  1121. [pan setDelegate:self];
  1122. [self.view addGestureRecognizer:pan];
  1123. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];
  1124. [tap setDelegate:self];
  1125. [self.view addGestureRecognizer:tap];
  1126. }
  1127. -(void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated{
  1128. MMDrawerSide drawerToHide = MMDrawerSideNone;
  1129. if(drawer == MMDrawerSideLeft){
  1130. drawerToHide = MMDrawerSideRight;
  1131. }
  1132. else if(drawer == MMDrawerSideRight){
  1133. drawerToHide = MMDrawerSideLeft;
  1134. }
  1135. UIViewController * sideDrawerViewControllerToPresent = [self sideDrawerViewControllerForSide:drawer];
  1136. UIViewController * sideDrawerViewControllerToHide = [self sideDrawerViewControllerForSide:drawerToHide];
  1137. [self.childControllerContainerView sendSubviewToBack:sideDrawerViewControllerToHide.view];
  1138. [sideDrawerViewControllerToHide.view setHidden:YES];
  1139. [sideDrawerViewControllerToPresent.view setHidden:NO];
  1140. [self resetDrawerVisualStateForDrawerSide:drawer];
  1141. [sideDrawerViewControllerToPresent.view setFrame:sideDrawerViewControllerToPresent.mm_visibleDrawerFrame];
  1142. [self updateDrawerVisualStateForDrawerSide:drawer percentVisible:0.0];
  1143. [sideDrawerViewControllerToPresent beginAppearanceTransition:YES animated:animated];
  1144. }
  1145. -(void)updateShadowForCenterView{
  1146. UIView * centerView = self.centerContainerView;
  1147. if(self.showsShadow){
  1148. centerView.layer.masksToBounds = NO;
  1149. centerView.layer.shadowRadius = self.shadowRadius;
  1150. centerView.layer.shadowOpacity = self.shadowOpacity;
  1151. centerView.layer.shadowOffset = self.shadowOffset;
  1152. centerView.layer.shadowColor = [self.shadowColor CGColor];
  1153. /** In the event this gets called a lot, we won't update the shadowPath
  1154. unless it needs to be updated (like during rotation) */
  1155. if (centerView.layer.shadowPath == NULL) {
  1156. centerView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:self.centerContainerView.bounds] CGPath];
  1157. }
  1158. else{
  1159. CGRect currentPath = CGPathGetPathBoundingBox(centerView.layer.shadowPath);
  1160. if (CGRectEqualToRect(currentPath, centerView.bounds) == NO){
  1161. centerView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:self.centerContainerView.bounds] CGPath];
  1162. }
  1163. }
  1164. }
  1165. else if (centerView.layer.shadowPath != NULL) {
  1166. centerView.layer.shadowRadius = 0.f;
  1167. centerView.layer.shadowOpacity = 0.f;
  1168. centerView.layer.shadowOffset = CGSizeMake(0, -3);
  1169. centerView.layer.shadowPath = NULL;
  1170. centerView.layer.masksToBounds = YES;
  1171. }
  1172. }
  1173. -(NSTimeInterval)animationDurationForAnimationDistance:(CGFloat)distance{
  1174. NSTimeInterval duration = MAX(distance/self.animationVelocity,MMDrawerMinimumAnimationDuration);
  1175. return duration;
  1176. }
  1177. -(UIViewController*)sideDrawerViewControllerForSide:(MMDrawerSide)drawerSide{
  1178. UIViewController * sideDrawerViewController = nil;
  1179. if(drawerSide != MMDrawerSideNone){
  1180. sideDrawerViewController = [self childViewControllerForSide:drawerSide];
  1181. }
  1182. return sideDrawerViewController;
  1183. }
  1184. -(UIViewController*)childViewControllerForSide:(MMDrawerSide)drawerSide{
  1185. UIViewController * childViewController = nil;
  1186. switch (drawerSide) {
  1187. case MMDrawerSideLeft:
  1188. childViewController = self.leftDrawerViewController;
  1189. break;
  1190. case MMDrawerSideRight:
  1191. childViewController = self.rightDrawerViewController;
  1192. break;
  1193. case MMDrawerSideNone:
  1194. childViewController = self.centerViewController;
  1195. break;
  1196. }
  1197. return childViewController;
  1198. }
  1199. #pragma mark - UIGestureRecognizerDelegate
  1200. -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
  1201. if(self.openSide == MMDrawerSideNone){
  1202. MMOpenDrawerGestureMode possibleOpenGestureModes = [self possibleOpenGestureModesForGestureRecognizer:gestureRecognizer
  1203. withTouch:touch];
  1204. return ((self.openDrawerGestureModeMask & possibleOpenGestureModes)>0);
  1205. }
  1206. else{
  1207. MMCloseDrawerGestureMode possibleCloseGestureModes = [self possibleCloseGestureModesForGestureRecognizer:gestureRecognizer
  1208. withTouch:touch];
  1209. return ((self.closeDrawerGestureModeMask & possibleCloseGestureModes)>0);
  1210. }
  1211. }
  1212. #pragma mark Gesture Recogizner Delegate Helpers
  1213. -(MMCloseDrawerGestureMode)possibleCloseGestureModesForGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer withTouch:(UITouch*)touch{
  1214. CGPoint point = [touch locationInView:self.childControllerContainerView];
  1215. MMCloseDrawerGestureMode possibleCloseGestureModes = MMCloseDrawerGestureModeNone;
  1216. if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]){
  1217. if([self isPointContainedWithinNavigationRect:point]){
  1218. possibleCloseGestureModes |= MMCloseDrawerGestureModeTapNavigationBar;
  1219. }
  1220. if([self isPointContainedWithinCenterViewContentRect:point]){
  1221. possibleCloseGestureModes |= MMCloseDrawerGestureModeTapCenterView;
  1222. }
  1223. }
  1224. else if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
  1225. if([self isPointContainedWithinNavigationRect:point]){
  1226. possibleCloseGestureModes |= MMCloseDrawerGestureModePanningNavigationBar;
  1227. }
  1228. if([self isPointContainedWithinCenterViewContentRect:point]){
  1229. possibleCloseGestureModes |= MMCloseDrawerGestureModePanningCenterView;
  1230. }
  1231. if([self isPointContainedWithinRightBezelRect:point] &&
  1232. self.openSide == MMDrawerSideLeft){
  1233. possibleCloseGestureModes |= MMCloseDrawerGestureModeBezelPanningCenterView;
  1234. }
  1235. if([self isPointContainedWithinLeftBezelRect:point] &&
  1236. self.openSide == MMDrawerSideRight){
  1237. possibleCloseGestureModes |= MMCloseDrawerGestureModeBezelPanningCenterView;
  1238. }
  1239. if([self isPointContainedWithinCenterViewContentRect:point] == NO &&
  1240. [self isPointContainedWithinNavigationRect:point] == NO){
  1241. possibleCloseGestureModes |= MMCloseDrawerGestureModePanningDrawerView;
  1242. }
  1243. }
  1244. if((self.closeDrawerGestureModeMask & MMCloseDrawerGestureModeCustom) > 0 &&
  1245. self.gestureShouldRecognizeTouch){
  1246. if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
  1247. possibleCloseGestureModes |= MMCloseDrawerGestureModeCustom;
  1248. }
  1249. }
  1250. return possibleCloseGestureModes;
  1251. }
  1252. -(MMOpenDrawerGestureMode)possibleOpenGestureModesForGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer withTouch:(UITouch*)touch{
  1253. CGPoint point = [touch locationInView:self.childControllerContainerView];
  1254. MMOpenDrawerGestureMode possibleOpenGestureModes = MMOpenDrawerGestureModeNone;
  1255. if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
  1256. if([self isPointContainedWithinNavigationRect:point]){
  1257. possibleOpenGestureModes |= MMOpenDrawerGestureModePanningNavigationBar;
  1258. }
  1259. if([self isPointContainedWithinCenterViewContentRect:point]){
  1260. possibleOpenGestureModes |= MMOpenDrawerGestureModePanningCenterView;
  1261. }
  1262. if([self isPointContainedWithinLeftBezelRect:point] &&
  1263. self.leftDrawerViewController){
  1264. possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
  1265. }
  1266. if([self isPointContainedWithinRightBezelRect:point] &&
  1267. self.rightDrawerViewController){
  1268. possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
  1269. }
  1270. }
  1271. if((self.openDrawerGestureModeMask & MMOpenDrawerGestureModeCustom) > 0 &&
  1272. self.gestureShouldRecognizeTouch){
  1273. if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
  1274. possibleOpenGestureModes |= MMOpenDrawerGestureModeCustom;
  1275. }
  1276. }
  1277. return possibleOpenGestureModes;
  1278. }
  1279. -(BOOL)isPointContainedWithinNavigationRect:(CGPoint)point{
  1280. CGRect navigationBarRect = CGRectNull;
  1281. if([self.centerViewController isKindOfClass:[UINavigationController class]]){
  1282. UINavigationBar * navBar = [(UINavigationController*)self.centerViewController navigationBar];
  1283. navigationBarRect = [navBar convertRect:navBar.bounds toView:self.childControllerContainerView];
  1284. navigationBarRect = CGRectIntersection(navigationBarRect,self.childControllerContainerView.bounds);
  1285. }
  1286. return CGRectContainsPoint(navigationBarRect,point);
  1287. }
  1288. -(BOOL)isPointContainedWithinCenterViewContentRect:(CGPoint)point{
  1289. CGRect centerViewContentRect = self.centerContainerView.frame;
  1290. centerViewContentRect = CGRectIntersection(centerViewContentRect,self.childControllerContainerView.bounds);
  1291. return (CGRectContainsPoint(centerViewContentRect, point) &&
  1292. [self isPointContainedWithinNavigationRect:point] == NO);
  1293. }
  1294. -(BOOL)isPointContainedWithinLeftBezelRect:(CGPoint)point{
  1295. CGRect leftBezelRect = CGRectNull;
  1296. CGRect tempRect;
  1297. CGRectDivide(self.childControllerContainerView.bounds, &leftBezelRect, &tempRect, self.bezelPanningCenterViewRange, CGRectMinXEdge);
  1298. return (CGRectContainsPoint(leftBezelRect, point) &&
  1299. [self isPointContainedWithinCenterViewContentRect:point]);
  1300. }
  1301. -(BOOL)isPointContainedWithinRightBezelRect:(CGPoint)point{
  1302. CGRect rightBezelRect = CGRectNull;
  1303. CGRect tempRect;
  1304. CGRectDivide(self.childControllerContainerView.bounds, &rightBezelRect, &tempRect, self.bezelPanningCenterViewRange, CGRectMaxXEdge);
  1305. return (CGRectContainsPoint(rightBezelRect, point) &&
  1306. [self isPointContainedWithinCenterViewContentRect:point]);
  1307. }
  1308. @end