dkahgld

WBSliderViewController.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. //
  2. // WBSliderViewController.m
  3. // WBSliderViewController
  4. //
  5. // Created by WB on 16/11/9.
  6. // Copyright © 2016年 WB. All rights reserved.
  7. //
  8. #import "WBSliderViewController.h"
  9. #define kWBDeviceWidth [UIScreen mainScreen].bounds.size.width
  10. #define kWBDeviceHeight [UIScreen mainScreen].bounds.size.height
  11. static NSTimeInterval const kAnimationDuration = 0.3;
  12. #pragma mark ---------- left config -----------
  13. static CGFloat const leftShowWidth = 240.f;//侧滑页面的大小
  14. static CGFloat const leftScale = 1.f;//是否布满整个页面
  15. static CGFloat const leftDragbleWidth = 80.f;//手势滑动距离边缘最少距离
  16. static CGFloat const leftMinDragLength = 100.f;////手势滑动距离边缘最大距离
  17. #pragma mark ---------- right config -----------
  18. static CGFloat const rightShowWidth = 240.f;
  19. static CGFloat const rightScale = 1.f;
  20. static CGFloat const rightDragbleWidth = 80.f;
  21. static CGFloat const rightMinDragLength = 100.f;
  22. typedef NS_ENUM(NSUInteger, WBDragDirection){
  23. WBDragDirectionNone = 0,
  24. WBDragDirectionLeft, // 左侧界面相关 show the leftView or hide
  25. WBDragDirectionRight,
  26. };
  27. @interface WBSliderViewController () <UIGestureRecognizerDelegate>
  28. @property (nonatomic,strong)UIView *mainContainerView;
  29. @property (nonatomic,strong)UIView *leftContainerView;
  30. @property (nonatomic,strong)UIView *rightContainerView;
  31. @property (nonatomic,strong)UIView *maskView;
  32. @property (nonatomic,assign)BOOL canShowLeft;
  33. @property (nonatomic,assign)BOOL canShowRight;
  34. @property (nonatomic,assign)BOOL isLeftShow;
  35. @property (nonatomic,assign)BOOL isRightShow;
  36. @property (nonatomic,assign)BOOL canDrag;
  37. @property (nonatomic,assign)CGPoint lastDragPoint;
  38. @property (nonatomic,assign)CGPoint startDragPoint;
  39. @property (nonatomic,assign) WBDragDirection dragDirection;
  40. @property (nonatomic,retain)UIPanGestureRecognizer *panGesture;
  41. @property (nonatomic,retain)UITapGestureRecognizer *tapGesture;
  42. @property (nonatomic, strong, readwrite) UIViewController *mainViewController;
  43. @property (nonatomic, strong, readwrite) UIViewController *leftViewController;
  44. @property (nonatomic, strong, readwrite) UIViewController *rightViewController;
  45. @end
  46. @implementation WBSliderViewController
  47. - (instancetype)initWithMainViewController:(UIViewController *)mainVC
  48. leftViewController:(UIViewController *)leftVC
  49. rightViewController:(UIViewController *)rightVC
  50. {
  51. self = [super init];
  52. if (self) {
  53. [self prepare];
  54. //左右边的控制器,哪个不想要,注释那句代码就可以
  55. self.mainViewController = mainVC;
  56. self.leftViewController = leftVC;
  57. self.rightViewController = rightVC;
  58. }
  59. return self;
  60. }
  61. - (void)prepare
  62. {
  63. CGRect view_bounds = self.view.bounds;
  64. _mainContainerView = [[UIView alloc] init];
  65. _leftContainerView = [[UIView alloc] init];
  66. _rightContainerView = [[UIView alloc] init];
  67. _maskView = [[UIView alloc] init];
  68. _maskView.hidden = YES;
  69. _mainContainerView.frame = view_bounds;
  70. _leftContainerView.frame = view_bounds;
  71. _rightContainerView.frame = view_bounds;
  72. _maskView.frame = view_bounds;
  73. [self.view addSubview:_leftContainerView];
  74. [self.view addSubview:_rightContainerView];
  75. [self.view addSubview:_mainContainerView];
  76. [_mainContainerView addSubview:_maskView];
  77. _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
  78. _panGesture.delegate = self;
  79. [_mainContainerView addGestureRecognizer:_panGesture];
  80. _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler)];
  81. [_maskView addGestureRecognizer:_tapGesture];
  82. UIView *backV =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  83. backV.tag=12345;
  84. backV.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.3];
  85. backV.hidden=YES;
  86. [backV addGestureRecognizer:_tapGesture];
  87. [self.view addSubview:backV];
  88. }
  89. -(void)viewDidDisappear:(BOOL)animated
  90. {
  91. [super viewDidDisappear:animated];
  92. _leftContainerView.hidden = YES;
  93. _rightContainerView.hidden = YES;
  94. }
  95. - (void)viewDidAppear:(BOOL)animated
  96. {
  97. [super viewDidAppear:animated];
  98. _leftContainerView.hidden = NO;
  99. _rightContainerView.hidden = NO;
  100. }
  101. #pragma mark -------------- property setter -----------------------
  102. - (void)setMainViewController:(UIViewController *)mainViewController
  103. {
  104. if (!mainViewController) {
  105. NSLog(@"mainViewController cannot be nil");
  106. return;
  107. }
  108. _mainViewController = mainViewController;
  109. [self addChildViewController:mainViewController];
  110. [_mainContainerView addSubview:mainViewController.view];
  111. }
  112. - (void)setLeftViewController:(UIViewController *)leftViewController
  113. {
  114. if (!leftViewController) {
  115. return;
  116. }
  117. _canShowLeft = YES;
  118. _leftViewController = leftViewController;
  119. _leftViewController.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  120. [self addChildViewController:leftViewController];
  121. [_leftContainerView addSubview:leftViewController.view];
  122. _leftContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -leftShowWidth, 0);
  123. _leftContainerView.transform = CGAffineTransformScale(_leftContainerView.transform, leftScale, leftScale);
  124. }
  125. - (void)setRightViewController:(UIViewController *)rightViewController
  126. {
  127. if (!rightViewController) {
  128. return;
  129. }
  130. _canShowRight = YES;
  131. _rightViewController = rightViewController;
  132. [self addChildViewController:rightViewController];
  133. [_rightContainerView addSubview:rightViewController.view];
  134. _rightViewController.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  135. [self addChildViewController:_rightViewController];
  136. [_rightContainerView addSubview:_rightViewController.view];
  137. _rightContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, rightShowWidth, 0);
  138. _rightContainerView.transform = CGAffineTransformScale(_rightContainerView.transform, rightScale, rightScale);
  139. }
  140. /**
  141. 控件左右菜单界面push所需要的navigationController,默认为mainVC的navigationController
  142. @return mainVC的navigationController
  143. */
  144. - (UINavigationController *)sliderNavigationController
  145. {
  146. if (self.mainViewController) {
  147. if ([self.mainViewController isKindOfClass:[UINavigationController class]]) {
  148. return (UINavigationController *)self.mainViewController;
  149. }
  150. }else if (self.mainViewController.navigationController){
  151. return self.mainViewController.navigationController;
  152. }
  153. return nil;
  154. }
  155. #pragma mark -------------- gesture delegate -----------------------
  156. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  157. {
  158. // 防止进入多级界面后依然可以呼出侧滑菜单栏
  159. if ([_mainViewController isKindOfClass:[UINavigationController class]]) {
  160. if (_mainViewController.childViewControllers.count>1) {
  161. return NO;
  162. }
  163. }else{
  164. for (UIViewController *controller in _mainViewController.childViewControllers) {
  165. if ([controller isKindOfClass:[UINavigationController class]]) {
  166. if (controller.childViewControllers.count>1) {
  167. return NO;
  168. }
  169. }
  170. }
  171. }
  172. // 判断点击拖动手势是否在允许拖动范围内
  173. if ([gestureRecognizer locationInView:_mainContainerView].x < leftDragbleWidth || [gestureRecognizer locationInView:_mainContainerView].x > kWBDeviceWidth-rightDragbleWidth) {
  174. return YES;
  175. }
  176. return NO;
  177. }
  178. #pragma mark -------------- gesture handle -----------------------
  179. - (void)tapGestureHandler
  180. {
  181. if (_isLeftShow) {
  182. [self hideLeft];
  183. }
  184. if (_isRightShow){
  185. [self hideRight];
  186. }
  187. }
  188. - (void)panGestureHandler:(UIPanGestureRecognizer *)gesture
  189. {
  190. CGPoint point = [gesture locationInView:self.view];
  191. switch (gesture.state) {
  192. case UIGestureRecognizerStateBegan:
  193. {
  194. // 判断是否响应拖动,记录拖动开始点位置
  195. if (!_isLeftShow&&!_isRightShow) {
  196. if (point.x<leftDragbleWidth||point.x>kWBDeviceWidth-rightDragbleWidth) {
  197. _canDrag = YES;
  198. }else{
  199. _canDrag = NO;
  200. }
  201. }else if (_isLeftShow){
  202. CGPoint curPoint = [gesture locationInView:_mainContainerView];
  203. if (curPoint.x>0&&curPoint.y>0) {
  204. _canDrag = YES;
  205. }else{
  206. _canDrag = NO;
  207. }
  208. }else if (_isRightShow){
  209. CGPoint curPoint = [gesture locationInView:_mainContainerView];
  210. if (curPoint.x>=0&&curPoint.y>=0) {
  211. _canDrag = YES;
  212. }else{
  213. _canDrag = NO;
  214. }
  215. }
  216. _startDragPoint = point;
  217. _lastDragPoint = point;
  218. }
  219. break;
  220. case UIGestureRecognizerStateChanged:
  221. {
  222. if (!_canDrag) {
  223. break;
  224. }
  225. CGFloat main_x = _mainContainerView.frame.origin.x;
  226. CGFloat move_length = point.x - _lastDragPoint.x;
  227. CGFloat scale = 1;
  228. _lastDragPoint = point;
  229. if (!_isLeftShow&&!_isRightShow) {
  230. if (_dragDirection == WBDragDirectionNone) {
  231. if (move_length>0) {
  232. _dragDirection = WBDragDirectionLeft;
  233. _leftContainerView.hidden = NO;
  234. _rightContainerView.hidden = YES;
  235. }else{
  236. _dragDirection = WBDragDirectionRight;
  237. _leftContainerView.hidden = YES;
  238. _rightContainerView.hidden = NO;
  239. }
  240. }
  241. switch (_dragDirection) {
  242. case WBDragDirectionLeft:
  243. {
  244. if (!_canShowLeft) {
  245. break;
  246. }
  247. if (_startDragPoint.x>kWBDeviceWidth-rightDragbleWidth||main_x+move_length<0) {
  248. // 防止拖拉左侧区域可以拖出右侧界面
  249. break;
  250. }
  251. CGFloat left_x = _leftContainerView.frame.origin.x;
  252. if (move_length>leftShowWidth||left_x>0||left_x+move_length>0) {
  253. // 判断界面变化是否应该停止
  254. break;
  255. }
  256. scale = 1-(move_length/leftShowWidth)*(1-leftScale);
  257. _mainContainerView.transform = CGAffineTransformTranslate(_mainContainerView.transform, move_length, 0);
  258. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, scale, scale);
  259. UIView *backV =[self.view viewWithTag:12345];
  260. backV.hidden=NO;
  261. backV.transform = CGAffineTransformTranslate(backV.transform, move_length, 0);
  262. backV.transform = CGAffineTransformScale(backV.transform, scale, scale);
  263. CGFloat left_scale = 1+(move_length/leftShowWidth)*(1-leftScale);
  264. _leftContainerView.transform = CGAffineTransformTranslate(_leftContainerView.transform, move_length, 0);
  265. _leftContainerView.transform = CGAffineTransformScale(_leftContainerView.transform, left_scale, left_scale);
  266. }
  267. break;
  268. case WBDragDirectionRight:
  269. {
  270. if (!_canShowRight) {
  271. break;
  272. }
  273. if (_startDragPoint.x<leftDragbleWidth||main_x+move_length>0) {
  274. // 防止拖拉右侧区域可以拖出左侧界面
  275. break;
  276. }
  277. CGFloat right_x = _rightContainerView.frame.origin.x;
  278. if (fabs(move_length)>rightShowWidth||right_x<0||right_x+move_length<0) {
  279. break;
  280. }
  281. scale = 1+(move_length/rightShowWidth)*(1-rightScale);
  282. _mainContainerView.transform = CGAffineTransformTranslate(_mainContainerView.transform, move_length, 0);
  283. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, scale, scale);
  284. UIView *backV =[self.view viewWithTag:12345];
  285. backV.hidden=NO;
  286. backV.transform = CGAffineTransformTranslate(backV.transform, move_length, 0);
  287. backV.transform = CGAffineTransformScale(backV.transform, scale, scale);
  288. CGFloat right_scale = 1-(move_length/rightShowWidth)*(1-rightScale);
  289. _rightContainerView.transform = CGAffineTransformTranslate(_rightContainerView.transform, move_length, 0);
  290. _rightContainerView.transform = CGAffineTransformScale(_rightContainerView.transform, right_scale, right_scale);
  291. }
  292. break;
  293. default:
  294. break;
  295. }
  296. }else if (_isLeftShow){
  297. if (_dragDirection == WBDragDirectionNone) {
  298. _dragDirection = WBDragDirectionLeft;
  299. }
  300. CGFloat left_x = _leftContainerView.frame.origin.x;
  301. if (fabs(move_length)>leftShowWidth||left_x>0||left_x+move_length>0||point.x>_startDragPoint.x||main_x<=0) {
  302. break;
  303. }
  304. scale = 1-(move_length/leftShowWidth)*(1-leftScale);
  305. _mainContainerView.transform = CGAffineTransformTranslate(_mainContainerView.transform, move_length, 0);
  306. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, scale, scale);
  307. UIView *backV =[self.view viewWithTag:12345];
  308. backV.hidden=NO;
  309. backV.transform = CGAffineTransformTranslate(backV.transform, move_length, 0);
  310. backV.transform = CGAffineTransformScale(backV.transform, scale, scale);
  311. CGFloat left_scale = 1+(move_length/leftShowWidth)*(1-leftScale);
  312. _leftContainerView.transform = CGAffineTransformTranslate(_leftContainerView.transform, move_length, 0);
  313. _leftContainerView.transform = CGAffineTransformScale(_leftContainerView.transform, left_scale, left_scale);
  314. }else if (_isRightShow){
  315. if (_dragDirection == WBDragDirectionNone) {
  316. _dragDirection = WBDragDirectionRight;
  317. }
  318. CGFloat right_x = _rightContainerView.frame.origin.x;
  319. if (move_length>rightShowWidth||right_x<0||right_x+move_length<0||point.x<_startDragPoint.x||main_x>=0) {
  320. break;
  321. }
  322. scale = 1+(move_length/rightShowWidth)*(1-rightScale);
  323. _mainContainerView.transform = CGAffineTransformTranslate(_mainContainerView.transform, move_length, 0);
  324. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, scale, scale);
  325. UIView *backV =[self.view viewWithTag:12345];
  326. backV.hidden=NO;
  327. backV.transform = CGAffineTransformTranslate(backV.transform, move_length, 0);
  328. backV.transform = CGAffineTransformScale(backV.transform, scale, scale);
  329. CGFloat right_scale = 1-(move_length/rightShowWidth)*(1-rightScale);
  330. _rightContainerView.transform = CGAffineTransformTranslate(_rightContainerView.transform, move_length, 0);
  331. _rightContainerView.transform = CGAffineTransformScale(_rightContainerView.transform, right_scale, right_scale);
  332. }
  333. }
  334. break;
  335. case UIGestureRecognizerStateEnded:
  336. {
  337. if (!_canDrag) {
  338. break;
  339. }
  340. CGFloat move_length = fabs(point.x - _startDragPoint.x);
  341. switch (_dragDirection) {
  342. case WBDragDirectionLeft:
  343. {
  344. CGFloat left_x = _leftContainerView.frame.origin.x;
  345. if (!_canShowLeft) {
  346. break;
  347. }
  348. if (_isLeftShow&&point.x-_startDragPoint.x>0&&left_x==0) {
  349. break;
  350. }
  351. if (move_length>leftMinDragLength) {
  352. if (_isLeftShow) {
  353. [self hideLeft];
  354. }else{
  355. [self showLeftWithType:_typepush];
  356. }
  357. }else{
  358. if (_isLeftShow) {
  359. [self showLeftWithType:_typepush];
  360. }else{
  361. [self hideLeft];
  362. }
  363. }
  364. }
  365. break;
  366. case WBDragDirectionRight:
  367. {
  368. CGFloat right_x = _rightContainerView.frame.origin.x;
  369. if (!_canShowRight) {
  370. break;
  371. }
  372. if (_isRightShow&&point.x-_startDragPoint.x<0&&right_x==0) {
  373. break;
  374. }
  375. if (move_length>rightMinDragLength) {
  376. if (_isRightShow) {
  377. [self hideRight];
  378. }else{
  379. [self showRight];
  380. }
  381. }else{
  382. if (_isRightShow) {
  383. [self showRight];
  384. }else{
  385. [self hideRight];
  386. }
  387. }
  388. }
  389. break;
  390. default:
  391. {
  392. [self hideLeft];
  393. [self hideRight];
  394. }
  395. break;
  396. }
  397. _dragDirection = WBDragDirectionNone;
  398. _lastDragPoint = CGPointZero;
  399. _startDragPoint = CGPointZero;
  400. _canDrag = NO;
  401. }
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407. #pragma mark -------------- calculate duration -----------------------
  408. - (NSTimeInterval)calculateAnimationDurationIsShow:(BOOL)isShow
  409. {
  410. NSTimeInterval timeInterval;
  411. CGFloat main_x = _mainContainerView.frame.origin.x;
  412. CGFloat left_x = _leftContainerView.frame.origin.x;
  413. CGFloat right_x = _rightContainerView.frame.origin.x;
  414. if (main_x==0||left_x==0||right_x==0) {
  415. return kAnimationDuration;
  416. }
  417. if (main_x>0) {
  418. // left
  419. CGFloat left_scale = _leftContainerView.frame.size.width/kWBDeviceWidth;
  420. if (isShow) {
  421. timeInterval = (1-(left_scale-leftScale)/(1-leftScale))*kAnimationDuration;
  422. } else {
  423. timeInterval = ((left_scale-leftScale)/(1-leftScale))*kAnimationDuration;
  424. }
  425. } else {
  426. // right
  427. CGFloat right_scale = _rightContainerView.frame.size.width/kWBDeviceWidth;
  428. if (isShow) {
  429. timeInterval = (1-(right_scale-rightScale)/(1-rightScale))*kAnimationDuration;
  430. } else {
  431. timeInterval = ((right_scale-rightScale)/(1-rightScale))*kAnimationDuration;
  432. }
  433. }
  434. return timeInterval;
  435. }
  436. #pragma mark -------------- public method -----------------------
  437. - (void)showLeftWithType:(NSString *)push
  438. {
  439. self.typepush = push;
  440. _leftContainerView.hidden = NO;
  441. _rightContainerView.hidden = YES;
  442. UIView *back= [self.view viewWithTag:12345];
  443. back.hidden=NO;
  444. [UIView animateWithDuration:[self calculateAnimationDurationIsShow:YES]
  445. animations:^{
  446. _mainContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, leftShowWidth, 0);
  447. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, leftScale, leftScale);
  448. _leftContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
  449. _leftContainerView.transform = CGAffineTransformScale(_leftContainerView.transform, 1, 1);
  450. back.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, leftShowWidth, 0);
  451. back.transform = CGAffineTransformScale(back.transform, leftScale, leftScale);
  452. }
  453. completion:^(BOOL finished) {
  454. _isLeftShow = YES;
  455. _maskView.hidden = NO;
  456. [_mainContainerView bringSubviewToFront:_maskView];
  457. }];
  458. }
  459. - (void)hideLeft
  460. {
  461. [UIView animateWithDuration:[self calculateAnimationDurationIsShow:NO]
  462. animations:^{
  463. UIView *back= [self.view viewWithTag:12345];
  464. back.hidden=YES;
  465. back.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
  466. back.transform = CGAffineTransformScale(back.transform, 1, 1);
  467. _mainContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
  468. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, 1, 1);
  469. _leftContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -leftShowWidth, 0);
  470. _leftContainerView.transform = CGAffineTransformScale(_leftContainerView.transform, leftScale, leftScale);
  471. }
  472. completion:^(BOOL finished) {
  473. _isLeftShow = NO;
  474. _maskView.hidden = YES;
  475. _leftContainerView.hidden = YES;
  476. }];
  477. }
  478. - (void)showRight
  479. {
  480. _leftContainerView.hidden = YES;
  481. _rightContainerView.hidden = NO;
  482. [UIView animateWithDuration:[self calculateAnimationDurationIsShow:YES]
  483. animations:^{
  484. _mainContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -rightShowWidth, 0);
  485. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, rightScale, rightScale);
  486. _rightContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
  487. _rightContainerView.transform = CGAffineTransformScale(_rightContainerView.transform, 1, 1);
  488. }
  489. completion:^(BOOL finished) {
  490. _isRightShow = YES;
  491. _maskView.hidden = NO;
  492. [_mainContainerView bringSubviewToFront:_maskView];
  493. }];
  494. }
  495. - (void)hideRight
  496. {
  497. [UIView animateWithDuration:[self calculateAnimationDurationIsShow:NO]
  498. animations:^{
  499. _mainContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
  500. _mainContainerView.transform = CGAffineTransformScale(_mainContainerView.transform, 1, 1);
  501. _rightContainerView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, rightShowWidth, 0);
  502. _rightContainerView.transform = CGAffineTransformScale(_rightContainerView.transform, rightScale, rightScale);
  503. }
  504. completion:^(BOOL finished) {
  505. _isRightShow = NO;
  506. _maskView.hidden = YES;
  507. _rightContainerView.hidden = YES;
  508. }];
  509. }
  510. @end