@@ -39,7 +39,6 @@ @interface YALContextMenuTableView ()
3939@property (nonatomic , strong ) UITableViewCell<YALContextMenuCell> *selectedCell;
4040@property (nonatomic , strong ) NSIndexPath *dismissalIndexpath;
4141@property (nonatomic ) AnimatingState animatingState;
42- @property (nonatomic ) YALPresenationType presentationType;
4342
4443@end
4544
@@ -62,7 +61,8 @@ - (instancetype)init {
6261 self.animatingState = Stable;
6362 self.animationDuration = defaultDuration;
6463 self.animatingIndex = 0 ;
65- self.presentationType = YALPresenationTypeRightToLeft;
64+ self.menuItemsSide = Right;
65+ self.menuItemsAppearanceDirection = FromTopToBottom;
6666
6767 self.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent: 0 .7f ];
6868 self.separatorColor = [UIColor colorWithRed: 181.0 /255.0 green: 181.0 /255.0 blue: 181.0 /255.0 alpha: 0 ];
@@ -72,9 +72,7 @@ - (instancetype)init {
7272}
7373
7474#pragma mark - Show / Dismiss
75- - (void )showInView : (UIView *)superview presentationType : (YALPresenationType)presentationType withEdgeInsets : (UIEdgeInsets)edgeInsets animated : (BOOL )animated {
76- self.presentationType = presentationType;
77-
75+ - (void )showInView : (UIView *)superview withEdgeInsets : (UIEdgeInsets)edgeInsets animated : (BOOL )animated {
7876 if (self.animatingState !=Stable) {
7977 return ;
8078 }
@@ -173,7 +171,12 @@ - (void)show:(BOOL)show visibleCellsAnimated:(BOOL)animated {
173171 if (visibleCell) {
174172 [self prepareCellForShowAnimation: visibleCell];
175173 [visibleCell contentView ].hidden = NO ;
176- Direction direction = (self.animatingIndex == firstVisibleRowIndex) ? [self directionForPresentation ] : top;
174+ Direction direction;
175+ if (self.animatingIndex == firstVisibleRowIndex) {
176+ direction = self.menuItemsSide == Right ? right : left;
177+ } else {
178+ direction = self.menuItemsAppearanceDirection == FromBottomToTop ? bottom : top;
179+ }
177180
178181 [self show: show cell: visibleCell animated: animated direction: direction clockwise: NO completion: ^(BOOL completed) {
179182 // ignore flag 'completed', cause if user scroll out animating cell, it will be false and menu will be empty(
@@ -190,7 +193,11 @@ - (void)show:(BOOL)show visibleCellsAnimated:(BOOL)animated {
190193- (void )dismissBottomCells {
191194 if (self.bottomCells .count ) {
192195 UITableViewCell<YALContextMenuCell> *hidingCell = [self .bottomCells lastObject ];
193- [self show: NO cell: hidingCell animated: YES direction: top clockwise: NO completion: ^(BOOL completed) {
196+ [self show: NO
197+ cell: hidingCell
198+ animated: YES
199+ direction: self .menuItemsAppearanceDirection == FromBottomToTop ? bottom : top
200+ clockwise: self .menuItemsAppearanceDirection == FromBottomToTop ? YES : NO completion: ^(BOOL completed) {
194201 if (completed) {
195202 [self .bottomCells removeLastObject ];
196203 [self dismissBottomCells ];
@@ -203,7 +210,11 @@ - (void)dismissBottomCells {
203210- (void )dismissTopCells {
204211 if (self.topCells .count ) {
205212 UITableViewCell<YALContextMenuCell> *hidingCell = [self .topCells firstObject ];
206- [self show: NO cell: hidingCell animated: YES direction: bottom clockwise: YES completion: ^(BOOL completed) {
213+ [self show: NO
214+ cell: hidingCell
215+ animated: YES
216+ direction: self .menuItemsAppearanceDirection == FromBottomToTop ? top : bottom
217+ clockwise: self .menuItemsAppearanceDirection == FromBottomToTop ? NO : YES completion: ^(BOOL completed) {
207218 if (completed) {
208219 [self .topCells removeObjectAtIndex: 0 ];
209220 [self dismissTopCells ];
@@ -214,8 +225,8 @@ - (void)dismissTopCells {
214225}
215226
216227- (void )dismissSelf {
217- Direction direction = [ self directionForPresentation ] ;
218- BOOL clockwise = [ self clockwiseRotationForPresentation ] ;
228+ Direction direction = self. menuItemsSide == Right ? right : left ;
229+ BOOL clockwise = self. menuItemsSide == Right ? NO : YES ;
219230 [self show: NO cell: self .selectedCell animated: YES direction: direction clockwise: clockwise completion: ^(BOOL completed) {
220231 [self removeFromSuperview ];
221232 if ([self .yalDelegate respondsToSelector: @selector (contextMenuTableView:didDismissWithIndexPath: )]) {
@@ -237,8 +248,15 @@ - (void)prepareCellForShowAnimation:(UITableViewCell<YALContextMenuCell> *)cell
237248
238249 [self resetAnimatedIconForCell: cell];
239250
240- Direction direction = ([self indexPathForCell: cell].row == 0 ) ? [self directionForPresentation ] : top;
241- BOOL clockwise = ([self indexPathForCell: cell].row == 0 ) ? [self clockwiseRotationForPresentation ] : NO ;
251+ Direction direction;
252+ BOOL clockwise;
253+ if ([self indexPathForCell: cell].row == 0 ) {
254+ direction = self.menuItemsSide == Right ? right : left;
255+ clockwise = self.menuItemsSide == Right ? NO : YES ;
256+ } else {
257+ direction = self.menuItemsAppearanceDirection == FromBottomToTop ? bottom : top;
258+ clockwise = self.menuItemsAppearanceDirection == FromBottomToTop ? YES : NO ;
259+ }
242260
243261 [self show: NO cell: cell animated: NO direction: direction clockwise: clockwise completion: nil ];
244262}
@@ -342,6 +360,9 @@ - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSI
342360 [cell contentView ].hidden = NO ;
343361 [cell animatedContent ].alpha = 1 ;
344362 }
363+ if (self.menuItemsAppearanceDirection == FromBottomToTop) {
364+ cell.layer .transform = CATransform3DRotate (CATransform3DIdentity, M_PI, 0 .0f , 0 .0f , 1 .0f );
365+ }
345366 }
346367 return cell;
347368}
@@ -375,29 +396,13 @@ - (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view {
375396 view.layer .anchorPoint = anchorPoint;
376397}
377398
378- - (Direction)directionForPresentation {
379- // Logic will be added
380- switch (self.presentationType ) {
381- case YALPresenationTypeRightToLeft:
382- return right;
383- break ;
384- case YALPresenationTypeLeftToRight:
385- return left;
386- break ;
387- }
388- }
389-
390- - (BOOL )clockwiseRotationForPresentation {
391- // Logic will be added
392- Direction direction = [self directionForPresentation ];
393- switch (direction) {
394- case left:
395- return YES ;
396- break ;
397- default :
398- return NO ;
399- break ;
399+ #pragma mark - Setters
400+ - (void )setMenuItemsAppearanceDirection : (MenuItemsAppearanceDirection)menuItemsAppearanceDirection {
401+ if (menuItemsAppearanceDirection != _menuItemsAppearanceDirection) {
402+ _menuItemsAppearanceDirection = menuItemsAppearanceDirection;
403+ if (self.menuItemsAppearanceDirection == FromBottomToTop) {
404+ self.layer .transform = CATransform3DRotate (CATransform3DIdentity, M_PI, 0 .0f , 0 .0f , 1 .0f );
400405 }
406+ }
401407}
402-
403408@end
0 commit comments