1818typedef void (^completionBlock)(BOOL completed);
1919
2020typedef NS_ENUM (NSUInteger , Direction) {
21+ left,
2122 right,
2223 top,
2324 bottom
@@ -38,6 +39,7 @@ @interface YALContextMenuTableView ()
3839@property (nonatomic , strong ) UITableViewCell<YALContextMenuCell> *selectedCell;
3940@property (nonatomic , strong ) NSIndexPath *dismissalIndexpath;
4041@property (nonatomic ) AnimatingState animatingState;
42+ @property (nonatomic ) YALPresenationType presentationType;
4143
4244@end
4345
@@ -60,6 +62,7 @@ - (instancetype)init {
6062 self.animatingState = Stable;
6163 self.animationDuration = defaultDuration;
6264 self.animatingIndex = 0 ;
65+ self.presentationType = YALPresenationTypeRightToLeft;
6366
6467 self.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent: 0 .7f ];
6568 self.separatorColor = [UIColor colorWithRed: 181.0 /255.0 green: 181.0 /255.0 blue: 181.0 /255.0 alpha: 0 ];
@@ -69,7 +72,8 @@ - (instancetype)init {
6972}
7073
7174#pragma mark - Show / Dismiss
72- - (void )showInView : (UIView *)superview withEdgeInsets : (UIEdgeInsets)edgeInsets animated : (BOOL )animated {
75+ - (void )showInView : (UIView *)superview presentationType : (YALPresenationType)presentationType withEdgeInsets : (UIEdgeInsets)edgeInsets animated : (BOOL )animated {
76+ self.presentationType = presentationType;
7377
7478 if (self.animatingState !=Stable) {
7579 return ;
@@ -169,7 +173,7 @@ - (void)show:(BOOL)show visibleCellsAnimated:(BOOL)animated {
169173 if (visibleCell) {
170174 [self prepareCellForShowAnimation: visibleCell];
171175 [visibleCell contentView ].hidden = NO ;
172- Direction direction = (self.animatingIndex == firstVisibleRowIndex) ? right : top;
176+ Direction direction = (self.animatingIndex == firstVisibleRowIndex) ? [ self directionForPresentation ] : top;
173177
174178 [self show: show cell: visibleCell animated: animated direction: direction clockwise: NO completion: ^(BOOL completed) {
175179 // ignore flag 'completed', cause if user scroll out animating cell, it will be false and menu will be empty(
@@ -210,7 +214,9 @@ - (void)dismissTopCells {
210214}
211215
212216- (void )dismissSelf {
213- [self show: NO cell: self .selectedCell animated: YES direction: right clockwise: NO completion: ^(BOOL completed) {
217+ Direction direction = [self directionForPresentation ];
218+ BOOL clockwise = [self clockwiseRotationForPresentation ];
219+ [self show: NO cell: self .selectedCell animated: YES direction: direction clockwise: clockwise completion: ^(BOOL completed) {
214220 [self removeFromSuperview ];
215221 if ([self .yalDelegate respondsToSelector: @selector (contextMenuTableView:didDismissWithIndexPath: )]) {
216222 [self .yalDelegate contextMenuTableView: self didDismissWithIndexPath: [self indexPathForCell: self .selectedCell]];
@@ -231,9 +237,10 @@ - (void)prepareCellForShowAnimation:(UITableViewCell<YALContextMenuCell> *)cell
231237
232238 [self resetAnimatedIconForCell: cell];
233239
234- Direction direction = ([self indexPathForCell: cell].row == 0 ) ? right : top;
240+ Direction direction = ([self indexPathForCell: cell].row == 0 ) ? [self directionForPresentation ] : top;
241+ BOOL clockwise = ([self indexPathForCell: cell].row == 0 ) ? [self clockwiseRotationForPresentation ] : NO ;
235242
236- [self show: NO cell: cell animated: NO direction: direction clockwise: NO completion: nil ];
243+ [self show: NO cell: cell animated: NO direction: direction clockwise: clockwise completion: nil ];
237244}
238245
239246/* !
@@ -276,6 +283,11 @@ - (void)show:(BOOL)show
276283 }
277284
278285 switch (direction) {
286+ case left: {
287+ [self setAnchorPoint: CGPointMake (0 , 0.5 ) forView: icon];
288+ rotationAndPerspectiveTransform = CATransform3DRotate (rotationAndPerspectiveTransform, DEGREES_TO_RADIANS (rotation), 0 .0f , 1 .0f , 0 .0f );
289+ break ;
290+ }
279291 case right: {
280292 [self setAnchorPoint: CGPointMake (1 , 0.5 ) forView: icon];
281293 rotationAndPerspectiveTransform = CATransform3DRotate (rotationAndPerspectiveTransform, DEGREES_TO_RADIANS (rotation), 0 .0f , 1 .0f , 0 .0f );
@@ -326,8 +338,7 @@ - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSI
326338 if (cell) {
327339 if (self.animatingState ==Showing) {
328340 [cell contentView ].hidden = YES ;
329- }else if (self.animatingState ==Stable)
330- {
341+ } else if (self.animatingState ==Stable) {
331342 [cell contentView ].hidden = NO ;
332343 [cell animatedContent ].alpha = 1 ;
333344 }
@@ -364,4 +375,29 @@ - (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view {
364375 view.layer .anchorPoint = anchorPoint;
365376}
366377
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 ;
400+ }
401+ }
402+
367403@end
0 commit comments