Skip to content

Commit 8af1ecc

Browse files
authored
Merge pull request #32 from lintx/master
change showInSuperView to uiwindow
2 parents 892080d + bb480b1 commit 8af1ecc

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Example/ContextMenu/ViewController.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ - (IBAction)presentMenuButtonTapped:(UIBarButtonItem *)sender {
8888
}
8989

9090
// it is better to use this method only for proper animation
91-
[self.contextMenuTableView showInView:self.navigationController.view withEdgeInsets:UIEdgeInsetsZero animated:YES];
91+
// [self.contextMenuTableView showInView:self.navigationController.view withEdgeInsets:UIEdgeInsetsZero animated:YES];
92+
[self.contextMenuTableView showWithAnimated:YES];
9293
}
9394

9495
#pragma mark - Local methods
@@ -143,4 +144,4 @@ - (UITableViewCell *)tableView:(YALContextMenuTableView *)tableView cellForRowAt
143144
return cell;
144145
}
145146

146-
@end
147+
@end

YALContextMenu/YALContextMenuTableView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef NS_ENUM(NSInteger, MenuItemsAppearanceDirection) {
7171
7272
@param YES or NO weather you want appearance animated or not.
7373
*/
74-
- (void)showInView:(UIView *)superview withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated;
74+
- (void)showWithAnimated:(BOOL)animated;
7575

7676
/*!
7777
@abstract

YALContextMenu/YALContextMenuTableView.m

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ @interface YALContextMenuTableView ()
3939
@property (nonatomic, strong) UITableViewCell<YALContextMenuCell> *selectedCell;
4040
@property (nonatomic, strong) NSIndexPath *dismissalIndexpath;
4141
@property (nonatomic) AnimatingState animatingState;
42+
@property (nonatomic, strong) UIWindow *window;
4243

4344
@end
4445

@@ -64,15 +65,22 @@ - (instancetype)init {
6465
self.menuItemsSide = Right;
6566
self.menuItemsAppearanceDirection = FromTopToBottom;
6667

67-
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7f];
68+
self.window = [[UIWindow alloc] init];
69+
self.window.windowLevel = UIWindowLevelStatusBar + 1.0f;
70+
self.window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7f];
71+
self.frame = self.window.frame;
72+
73+
// self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7f];
74+
self.backgroundColor = [UIColor clearColor];
6875
self.separatorColor = [UIColor colorWithRed:181.0/255.0 green:181.0/255.0 blue:181.0/255.0 alpha:0];
6976
self.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //Zero rect footer to clear empty rows UITableView draws
77+
// [self.window addSubview:self];
7078
}
7179
return self;
7280
}
7381

7482
#pragma mark - Show / Dismiss
75-
- (void)showInView:(UIView *)superview withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated {
83+
- (void)showWithAnimated:(BOOL)animated{
7684
if (self.animatingState!=Stable) {
7785
return;
7886
}
@@ -83,16 +91,17 @@ - (void)showInView:(UIView *)superview withEdgeInsets:(UIEdgeInsets)edgeInsets a
8391

8492
self.dismissalIndexpath = nil;
8593

86-
[superview addSubViewiew:self withSidesConstrainsInsets:edgeInsets];
94+
[self.window addSubview:self];
95+
self.window.hidden = NO;
8796

8897
if (animated) {
8998
self.animatingState = Showing;
90-
self.alpha = 0;
99+
self.window.alpha = 0;
91100

92101
[self setUserInteractionEnabled:NO];
93102

94103
[UIView animateWithDuration:self.animationDuration animations:^{
95-
self.alpha = 1;
104+
self.window.alpha = 1;
96105
} completion:^(BOOL finished) {
97106
[self show:YES visibleCellsAnimated:YES];
98107
[self setUserInteractionEnabled:YES];
@@ -231,6 +240,7 @@ - (void)dismissSelf {
231240
BOOL clockwise = self.menuItemsSide == Right ? NO : YES;
232241
[self show:NO cell:self.selectedCell animated:YES direction:direction clockwise:clockwise completion:^(BOOL completed) {
233242
[self removeFromSuperview];
243+
self.window.hidden = YES;
234244
if ([self.yalDelegate respondsToSelector:@selector(contextMenuTableView:didDismissWithIndexPath:)]) {
235245
[self.yalDelegate contextMenuTableView:self didDismissWithIndexPath:[self indexPathForCell:self.selectedCell]];
236246
}
@@ -248,7 +258,7 @@ - (void)shouldDismissSelf {
248258

249259
- (void)prepareCellForShowAnimation:(UITableViewCell<YALContextMenuCell> *)cell {
250260

251-
[self resetAnimatedIconForCell:cell];
261+
// [self resetAnimatedIconForCell:cell];
252262

253263
Direction direction;
254264
BOOL clockwise;

0 commit comments

Comments
 (0)