Skip to content

Commit 1ed23e5

Browse files
committed
added from bottom layout
1 parent e1e0d57 commit 1ed23e5

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

Example/ContextMenu/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ - (IBAction)presentMenuButtonTapped:(UIBarButtonItem *)sender {
8585
}
8686

8787
// it is better to use this method only for proper animation
88-
[self.contextMenuTableView showInView:self.navigationController.view presentationType:YALPresenationTypeRightToLeft withEdgeInsets:UIEdgeInsetsZero animated:YES];
88+
[self.contextMenuTableView showInView:self.navigationController.view withEdgeInsets:UIEdgeInsetsZero animated:YES];
8989
}
9090

9191
#pragma mark - Local methods

YALContextMenu/YALContextMenuTableView.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
typedef NS_ENUM(NSInteger, YALPresenationType) {
12-
YALPresenationTypeRightToLeft,
13-
YALPresenationTypeLeftToRight
11+
typedef NS_ENUM(NSInteger, MenuItemsSide) {
12+
Left,
13+
Right
14+
};
15+
16+
typedef NS_ENUM(NSInteger, MenuItemsAppearanceDirection) {
17+
FromTopToBottom,
18+
FromBottomToTop
1419
};
1520

1621
@class YALContextMenuTableView;
@@ -34,11 +39,16 @@ typedef NS_ENUM(NSInteger, YALPresenationType) {
3439

3540
@interface YALContextMenuTableView : UITableView
3641

37-
@property (nonatomic, weak) id<YALContextMenuTableViewDelegate>yalDelegate;
42+
@property (nonatomic, weak) id <YALContextMenuTableViewDelegate> yalDelegate;
3843

3944
/*! @abstract animationDuration time for animation in seconds*/
4045
@property (nonatomic) CGFloat animationDuration;
4146

47+
/*! The side of the screen to which menu items are related(For example, if 'right' chosen then first cell will be opened from right to left and counterclockwise and menu will be closed clockwise). Default - Right.*/
48+
@property (nonatomic) MenuItemsSide menuItemsSide;
49+
50+
/*! @abstract Direction if menu item appearence. Default - FromTopToBottom.*/
51+
@property (nonatomic) MenuItemsAppearanceDirection menuItemsAppearanceDirection;
4252

4353
/*!
4454
@abstract
@@ -56,11 +66,9 @@ typedef NS_ENUM(NSInteger, YALPresenationType) {
5666
5767
@param Superview to present your menu. If you are using a navigation controller it is better to use myViewController.navigationController.view as a suoerview.
5868
59-
@param presentationType depends on position of your cell's animatedIcon(On the right side of the screen - YALPresenationTypeRightToLeft, otherwise - YALPresenationTypeLeftToRight). Default is YALPresenationTypeRightToLeft.
60-
6169
@param YES or NO weather you want appearance animated or not.
6270
*/
63-
- (void)showInView:(UIView *)superview presentationType:(YALPresenationType)presentationType withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated;
71+
- (void)showInView:(UIView *)superview withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated;
6472

6573
/*!
6674
@abstract

YALContextMenu/YALContextMenuTableView.m

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)