Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RDActionSheet/RDActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef void(^CallbackBlock)(RDActionSheetResult result, NSInteger buttonIndex);

- (id)initWithDelegate:(NSObject <RDActionSheetDelegate> *)aDelegate cancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destroyButtonTitle:(NSString *)destroyButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... __attribute__ ((deprecated));
- (id)initWithCancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destroyButtonTitle:(NSString *)destroyButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;
- (id)initWithCancelButtonTitleWithNSArray:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destroyButtonTitle:(NSString *)destroyButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles;
- (void)showFrom:(UIView *)view;
- (void)cancelActionSheet;

Expand Down
112 changes: 89 additions & 23 deletions RDActionSheet/RDActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <QuartzCore/QuartzCore.h>

@interface RDActionSheet ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *buttons;
@property (nonatomic, strong) UIView *blackOutView;

Expand Down Expand Up @@ -48,6 +48,8 @@ @implementation RDActionSheet
@synthesize buttons;
@synthesize blackOutView;

@synthesize scrollView;

#pragma mark - Initialization

- (id)init {
Expand All @@ -62,7 +64,7 @@ - (id)init {
return self;
}

- (id)initWithDelegate:(NSObject<RDActionSheetDelegate> *)aDelegate cancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destroyButtonTitle:(NSString *)destroyButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... {
- (id)initWithDelegate:(NSObject<RDActionSheetDelegate,UIScrollViewDelegate> *)aDelegate cancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destroyButtonTitle:(NSString *)destroyButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... {

self = [self initWithCancelButtonTitle:cancelButtonTitle primaryButtonTitle:primaryButtonTitle destroyButtonTitle:destroyButtonTitle otherButtonTitles:otherButtonTitles];
if (self) {
Expand All @@ -77,7 +79,7 @@ - (id)initWithCancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle
self = [self init];
if (self) {

// Build normal buttons
// Build normal buttons[mArray getObjects:objects range:range];
va_list argumentList;
va_start(argumentList, otherButtonTitles);

Expand All @@ -95,18 +97,64 @@ - (id)initWithCancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle
// Build cancel button
UIButton *cancelButton = [self buildCancelButtonWithTitle:cancelButtonTitle];
[self.buttons insertObject:cancelButton atIndex:0];
/*
// Add primary button
if (primaryButtonTitle) {
UIButton *primaryButton = [self buildPrimaryButtonWithTitle:primaryButtonTitle];
[self.buttons addObject:primaryButton];
}

// Add destroy button
if (destroyButtonTitle) {
UIButton *destroyButton = [self buildDestroyButtonWithTitle:destroyButtonTitle];
[self.buttons insertObject:destroyButton atIndex:1];
}
*/
}

return self;
}

- (id)initWithCancelButtonTitleWithNSArray:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destroyButtonTitle:(NSString *)destroyButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles {

self = [self init];
if (self) {
// Build normal buttons[mArray getObjects:objects range:range];
//va_list argumentList;
//va_start(argumentList, otherButtonTitles);

// Add primary button
if (primaryButtonTitle) {
UIButton *primaryButton = [self buildPrimaryButtonWithTitle:primaryButtonTitle];
[self.buttons addObject:primaryButton];
//NSString *argString = otherButtonTitles;
for (int x = 0; x<[otherButtonTitles count]; x++) {
UIButton *button = [self buildButtonWithTitle:[otherButtonTitles objectAtIndex:x]];
[self.buttons addObject:button];
}

// Add destroy button
if (destroyButtonTitle) {
UIButton *destroyButton = [self buildDestroyButtonWithTitle:destroyButtonTitle];
[self.buttons insertObject:destroyButton atIndex:1];
}
/*
while (argString != nil) {

UIButton *button = [self buildButtonWithTitle:argString];
[self.buttons addObject:button];

argString = va_arg(argumentList, NSString *);
}

va_end(argumentList);
*/
// Build cancel button
UIButton *cancelButton = [self buildCancelButtonWithTitle:cancelButtonTitle];
[self.buttons insertObject:cancelButton atIndex:0];
/*
// Add primary button
if (primaryButtonTitle) {
UIButton *primaryButton = [self buildPrimaryButtonWithTitle:primaryButtonTitle];
[self.buttons addObject:primaryButton];
}

// Add destroy button
if (destroyButtonTitle) {
UIButton *destroyButton = [self buildDestroyButtonWithTitle:destroyButtonTitle];
[self.buttons insertObject:destroyButton atIndex:1];
}
*/
}

return self;
Expand Down Expand Up @@ -222,7 +270,7 @@ - (UIButton *)buildButtonWithTitle:(NSString *)title {
[button setBackgroundImage:backgroundImage forState:UIControlStateNormal];

UIImage *touchBackgroundImage = [[UIImage imageNamed:@"SheetButtonGenericTouch.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:1];
[button setBackgroundImage:touchBackgroundImage forState:UIControlStateHighlighted];
[button setBackgroundImage:touchBackgroundImage forState:UIControlEventTouchUpInside];

button.titleLabel.layer.shadowColor = [UIColor whiteColor].CGColor;
button.titleLabel.layer.shadowRadius = 0.0;
Expand Down Expand Up @@ -302,7 +350,7 @@ - (void)buttonWasPressed:(id)button {
}

- (void)cancelActionSheet {

[UIView animateWithDuration:kActionSheetAnimationTime animations:^{

CGFloat endPosition = self.frame.origin.y + self.frame.size.height;
Expand All @@ -324,21 +372,39 @@ - (void)cancelActionSheet {
}

#pragma mark - Present action sheet

- (void)scrollViewDidScroll:(UIScrollView *)scrollViewInstance {
if (scrollViewInstance.contentOffset.y > 60) {
[scrollViewInstance setContentOffset:CGPointMake(0, 60)];
}
}
- (void)showFrom:(UIView *)view {

CGFloat startPosition = view.bounds.origin.y + view.bounds.size.height;
self.frame = CGRectMake(0, startPosition, view.bounds.size.width, [self calculateSheetHeight]);
[view addSubview:self];

self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, startPosition, view.bounds.size.width, view.bounds.size.height)];
self.scrollView.bounces = NO;
self.scrollView.contentSize = CGSizeMake(view.bounds.size.width,[self calculateSheetHeight]);
[self.scrollView addSubview:self];
CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:YES];
[self.scrollView bringSubviewToFront:self];
[view bringSubviewToFront:self.scrollView];
[view addSubview:self.scrollView];

self.blackOutView = [self buildBlackOutViewWithFrame:view.bounds];
[view insertSubview:self.blackOutView belowSubview:self];
[view insertSubview:self.blackOutView belowSubview:self.scrollView];

[UIView animateWithDuration:kActionSheetAnimationTime animations:^{
CGFloat endPosition = startPosition - self.frame.size.height;
CGFloat endPosition = startPosition - self.scrollView.frame.size.height;
self.frame = CGRectMake(self.frame.origin.x, endPosition, self.frame.size.width, self.frame.size.height);
self.blackOutView.alpha = kBlackoutViewFadeInOpacity;
}];
}];

[UIView animateWithDuration:kActionSheetAnimationTime animations:^{
CGFloat endPosition = startPosition - self.scrollView.frame.size.height;
self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, endPosition, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
self.blackOutView.alpha = kBlackoutViewFadeInOpacity;
}];
}

#pragma mark - Helpers
Expand Down