|
@@ -25,7 +25,7 @@ static const CGFloat kFlickDownMinVelocity = 2000.0f;
|
|
|
// How much free space to leave at the top (above the tableView's contents) when there's a lot of elements. It makes this control look similar to the UIActionSheet.
|
|
|
static const CGFloat kTopSpaceMarginFraction = 0.0f;
|
|
|
// cancelButton's shadow height as the ratio to the cancelButton's height
|
|
|
-static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
+static const CGFloat kSpaceDivide = 5.0f;
|
|
|
|
|
|
|
|
|
/// Used for storing button configuration.
|
|
@@ -81,7 +81,7 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
NSForegroundColorAttributeName : [UIColor redColor] }];
|
|
|
[appearance setTitleTextAttributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:14.0f],
|
|
|
NSForegroundColorAttributeName : [UIColor grayColor] }];
|
|
|
- [appearance setCancelOnPanGestureEnabled:@(YES)];
|
|
|
+ [appearance setCancelOnPanGestureEnabled:@(NO)];
|
|
|
[appearance setCancelOnTapEmptyAreaEnabled:@(NO)];
|
|
|
[appearance setAnimationDuration:kDefaultAnimationDuration];
|
|
|
}
|
|
@@ -138,7 +138,7 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
{
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier forIndexPath:indexPath];
|
|
|
|
|
|
- cell.separatorInset = UIEdgeInsetsMake(0.f, 55.f, 0.f, 0.f);
|
|
|
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
AHKActionSheetItem *item = self.items[(NSUInteger)indexPath.row];
|
|
|
|
|
@@ -199,27 +199,52 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
return item.height;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
--(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
{
|
|
|
- // Remove separator inset as described here: http://stackoverflow.com/a/25877725/783960
|
|
|
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
|
|
|
- [cell setSeparatorInset:UIEdgeInsetsZero];
|
|
|
- }
|
|
|
+ AHKActionSheetItem *item = self.items[(NSUInteger)indexPath.row];
|
|
|
|
|
|
- // Prevent the cell from inheriting the Table View's margin settings
|
|
|
- if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
|
|
|
- [cell setPreservesSuperviewLayoutMargins:NO];
|
|
|
+ CGFloat cornerRadius = 10.f;
|
|
|
+ cell.backgroundColor = UIColor.clearColor;
|
|
|
+ CAShapeLayer *layer = [[CAShapeLayer alloc] init];
|
|
|
+ CGMutablePathRef pathRef = CGPathCreateMutable();
|
|
|
+ CGRect bounds = CGRectInset(cell.bounds, 10, 0);
|
|
|
+ BOOL addLine = NO;
|
|
|
+
|
|
|
+ if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
|
|
|
+ CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
|
|
|
+ } else if (indexPath.row == 0) {
|
|
|
+ CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
|
|
|
+ CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
|
|
|
+ CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
|
|
|
+ CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
|
|
|
+ addLine = YES;
|
|
|
+ } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
|
|
|
+ CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
|
|
|
+ CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
|
|
|
+ CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
|
|
|
+ CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
|
|
|
+ } else {
|
|
|
+ CGPathAddRect(pathRef, nil, bounds);
|
|
|
+ addLine = YES;
|
|
|
}
|
|
|
|
|
|
- // Explictly set your cell's layout margins
|
|
|
- if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
|
|
|
- [cell setLayoutMargins:UIEdgeInsetsZero];
|
|
|
+ layer.path = pathRef;
|
|
|
+ CFRelease(pathRef);
|
|
|
+ layer.fillColor = item.backgroundColor.CGColor;
|
|
|
+
|
|
|
+ if (addLine == YES) {
|
|
|
+ CALayer *lineLayer = [[CALayer alloc] init];
|
|
|
+ CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
|
|
|
+ lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);
|
|
|
+ lineLayer.backgroundColor = tableView.separatorColor.CGColor;
|
|
|
+ [layer addSublayer:lineLayer];
|
|
|
}
|
|
|
+
|
|
|
+ UIView *testView = [[UIView alloc] initWithFrame:bounds];
|
|
|
+ [testView.layer insertSublayer:layer atIndex:0];
|
|
|
+ testView.backgroundColor = UIColor.clearColor;
|
|
|
+ cell.backgroundView = testView;
|
|
|
}
|
|
|
-*/
|
|
|
-
|
|
|
-
|
|
|
|
|
|
#pragma mark - UIScrollViewDelegate
|
|
|
|
|
@@ -316,17 +341,18 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
};
|
|
|
|
|
|
void(^delayedAnimations)(void) = ^(void) {
|
|
|
- self.cancelButton.frame = CGRectMake(0,
|
|
|
- CGRectGetMaxY(self.bounds) - self.cancelButtonHeight,
|
|
|
- CGRectGetWidth(self.bounds),
|
|
|
- self.cancelButtonHeight);
|
|
|
+
|
|
|
+ self.cancelButton.frame = CGRectMake(10, CGRectGetMaxY(self.bounds) - self.cancelButtonHeight, CGRectGetWidth(self.bounds) - 20, self.cancelButtonHeight - kSpaceDivide);
|
|
|
|
|
|
+ // Corner Radius
|
|
|
+ self.cancelButton.layer.cornerRadius = 10;
|
|
|
+ self.cancelButton.clipsToBounds = YES;
|
|
|
+
|
|
|
// Add White color background
|
|
|
self.cancelButton.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
self.tableView.transform = CGAffineTransformMakeTranslation(0, 0);
|
|
|
|
|
|
-
|
|
|
// manual calculation of table's contentSize.height
|
|
|
CGFloat tableContentHeight = 0; //[self.items count] * self.buttonHeight + CGRectGetHeight(self.tableView.tableHeaderView.frame);
|
|
|
for (AHKActionSheetItem *item in self.items) {
|
|
@@ -411,7 +437,7 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
// animate sliding down tableView and cancelButton.
|
|
|
[UIView animateWithDuration:duration animations:^{
|
|
|
self.blurredBackgroundView.alpha = 0.0f;
|
|
|
- self.cancelButton.transform = CGAffineTransformTranslate(self.cancelButton.transform, 0, self.cancelButtonHeight);
|
|
|
+ self.cancelButton.transform = CGAffineTransformTranslate(self.cancelButton.transform, 0, self.cancelButtonHeight - kSpaceDivide);
|
|
|
self.cancelButtonShadowView.alpha = 0.0f;
|
|
|
|
|
|
// Shortest shift of position sufficient to hide all tableView contents below the bottom margin.
|
|
@@ -468,33 +494,17 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
}
|
|
|
|
|
|
- NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:self.cancelButtonTitle
|
|
|
- attributes:self.cancelButtonTextAttributes];
|
|
|
+ NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:self.cancelButtonTitle attributes:self.cancelButtonTextAttributes];
|
|
|
+
|
|
|
[cancelButton setAttributedTitle:attrTitle forState:UIControlStateNormal];
|
|
|
[cancelButton addTarget:self action:@selector(cancelButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- cancelButton.frame = CGRectMake(0,
|
|
|
- CGRectGetMaxY(self.bounds) - self.cancelButtonHeight,
|
|
|
- CGRectGetWidth(self.bounds),
|
|
|
- self.cancelButtonHeight);
|
|
|
+
|
|
|
// move the button below the screen (ready to be animated -show)
|
|
|
- cancelButton.transform = CGAffineTransformMakeTranslation(0, self.cancelButtonHeight);
|
|
|
+ cancelButton.transform = CGAffineTransformMakeTranslation(0, self.cancelButtonHeight - kSpaceDivide);
|
|
|
cancelButton.clipsToBounds = YES;
|
|
|
[self addSubview:cancelButton];
|
|
|
|
|
|
self.cancelButton = cancelButton;
|
|
|
-
|
|
|
- // add a small shadow/glow above the button
|
|
|
- if (self.cancelButtonShadowColor) {
|
|
|
- self.cancelButton.clipsToBounds = NO;
|
|
|
- CGFloat gradientHeight = (CGFloat)round(self.cancelButtonHeight * kCancelButtonShadowHeightRatio);
|
|
|
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -gradientHeight, CGRectGetWidth(self.bounds), gradientHeight)];
|
|
|
- CAGradientLayer *gradient = [CAGradientLayer layer];
|
|
|
- gradient.frame = view.bounds;
|
|
|
- gradient.colors = @[ (id)[UIColor colorWithWhite:0.0 alpha:0.0].CGColor, (id)[self.blurTintColor colorWithAlphaComponent:0.1f].CGColor ];
|
|
|
- [view.layer insertSublayer:gradient atIndex:0];
|
|
|
- [self.cancelButton addSubview:view];
|
|
|
- self.cancelButtonShadowView = view;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- (void)setUpTableView
|
|
@@ -507,8 +517,10 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
|
|
|
CGRectGetHeight(self.bounds) - statusBarHeight - self.cancelButtonHeight);
|
|
|
|
|
|
UITableView *tableView = [[UITableView alloc] initWithFrame:frame];
|
|
|
+
|
|
|
tableView.backgroundColor = [UIColor clearColor];
|
|
|
tableView.showsVerticalScrollIndicator = NO;
|
|
|
+ tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
|
|
if (self.separatorColor) {
|
|
|
tableView.separatorColor = self.separatorColor;
|