react-native-navigation的迁移库

MMDrawerController.m 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  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