Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Adds ability to tweet bounce dynamics values
Browse files Browse the repository at this point in the history
  • Loading branch information
erichoracek committed Nov 13, 2013
1 parent 7f6dbef commit f6098ba
Showing 1 changed file with 121 additions and 35 deletions.
156 changes: 121 additions & 35 deletions Example/Example/MSBounceViewController.m
Expand Up @@ -29,6 +29,14 @@
#import "MSBounceViewController.h"

NSString * const MSBounceCellReuseIdentifier = @"Bounce Cell";
NSString * const MSBounceDynamicsCellReuseIdentifier = @"Bounce Dynamics Cell";

typedef NS_ENUM(NSInteger, MSBounceSectionType) {
MSBounceSectionTypeBounce,
MSBounceSectionTypeBounceMagnitude,
MSBounceSectionTypeBounceElasticity,
MSBounceSectionTypeCount,
};

@implementation MSBounceViewController

Expand All @@ -38,6 +46,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MSBounceCellReuseIdentifier];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MSBounceDynamicsCellReuseIdentifier];
}

#pragma mark - UITableViewController
Expand All @@ -48,61 +57,133 @@ - (instancetype)initWithStyle:(UITableViewStyle)style
return self;
}

#pragma mark - MSDynamicsViewController

- (void)sliderDidUpdateValue:(UISlider *)slider
{
MSDynamicsDrawerViewController *dynamicsDrawerViewController = (MSDynamicsDrawerViewController *)self.navigationController.parentViewController;
switch (slider.tag) {
case MSBounceSectionTypeBounceMagnitude:
dynamicsDrawerViewController.bounceMagnitude = slider.value;
break;
case MSBounceSectionTypeBounceElasticity:
dynamicsDrawerViewController.bounceElasticity = slider.value;
break;
}
[self.tableView reloadData];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return MSBounceSectionTypeCount;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
MSDynamicsDrawerViewController *dynamicsDrawerViewController = (MSDynamicsDrawerViewController *)self.navigationController.parentViewController;
NSInteger possibleDrawerDirection = dynamicsDrawerViewController.possibleDrawerDirection;
__block NSInteger possibleDirectionCount = 0;
MSDynamicsDrawerDirectionActionForMaskedValues(possibleDrawerDirection, ^(MSDynamicsDrawerDirection maskedValue) {
possibleDirectionCount++;
});
return possibleDirectionCount;
switch (section) {
case MSBounceSectionTypeBounce: {
MSDynamicsDrawerViewController *dynamicsDrawerViewController = (MSDynamicsDrawerViewController *)self.navigationController.parentViewController;
NSInteger possibleDrawerDirection = dynamicsDrawerViewController.possibleDrawerDirection;
__block NSInteger possibleDirectionCount = 0;
MSDynamicsDrawerDirectionActionForMaskedValues(possibleDrawerDirection, ^(MSDynamicsDrawerDirection maskedValue) {
possibleDirectionCount++;
});
return possibleDirectionCount;
}
default:
return 1;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MSBounceCellReuseIdentifier forIndexPath:indexPath];

MSDynamicsDrawerViewController *dynamicsDrawerViewController = (MSDynamicsDrawerViewController *)self.navigationController.parentViewController;
NSInteger possibleDrawerDirection = dynamicsDrawerViewController.possibleDrawerDirection;
__block NSInteger possibleDrawerDirectionRow = 0;
MSDynamicsDrawerDirectionActionForMaskedValues(possibleDrawerDirection, ^(MSDynamicsDrawerDirection maskedValue) {
if (indexPath.row == possibleDrawerDirectionRow) {
NSString *title;
switch (maskedValue) {
case MSDynamicsDrawerDirectionLeft:
title = @"";
break;
case MSDynamicsDrawerDirectionRight:
title = @"";
break;
case MSDynamicsDrawerDirectionTop:
title = @"";
break;
case MSDynamicsDrawerDirectionBottom:
title = @"";
switch (indexPath.section) {
case MSBounceSectionTypeBounce: {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MSBounceCellReuseIdentifier forIndexPath:indexPath];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = self.view.window.tintColor;

MSDynamicsDrawerViewController *dynamicsDrawerViewController = (MSDynamicsDrawerViewController *)self.navigationController.parentViewController;
NSInteger possibleDrawerDirection = dynamicsDrawerViewController.possibleDrawerDirection;
__block NSInteger possibleDrawerDirectionRow = 0;
MSDynamicsDrawerDirectionActionForMaskedValues(possibleDrawerDirection, ^(MSDynamicsDrawerDirection maskedValue) {
if (indexPath.row == possibleDrawerDirectionRow) {
NSString *title;
switch (maskedValue) {
case MSDynamicsDrawerDirectionLeft:
title = @"";
break;
case MSDynamicsDrawerDirectionRight:
title = @"";
break;
case MSDynamicsDrawerDirectionTop:
title = @"";
break;
case MSDynamicsDrawerDirectionBottom:
title = @"";
break;
default:
break;
}
cell.textLabel.text = title;
}
possibleDrawerDirectionRow++;
});
return cell;
}
default: {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MSBounceDynamicsCellReuseIdentifier forIndexPath:indexPath];
MSDynamicsDrawerViewController *dynamicsDrawerViewController = (MSDynamicsDrawerViewController *)self.navigationController.parentViewController;
UISlider *slider = (UISlider *)cell.accessoryView;
if (!slider || ![slider isKindOfClass:[UISlider class]]) {
slider = [UISlider new];
[slider addTarget:self action:@selector(sliderDidUpdateValue:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = slider;
}
slider.frame = (CGRect){slider.frame.origin, {200.0, slider.frame.size.height}};
slider.tag = indexPath.section;
switch (indexPath.section) {
case MSBounceSectionTypeBounceMagnitude: {
slider.minimumValue = 0.0;
slider.maximumValue = 200.0;
slider.value = dynamicsDrawerViewController.bounceMagnitude;
break;
default:
}
case MSBounceSectionTypeBounceElasticity: {
slider.minimumValue = 0.0;
slider.maximumValue = 1.0;
slider.value = dynamicsDrawerViewController.bounceElasticity;
break;
}
}
cell.textLabel.text = title;
cell.textLabel.text = [NSString stringWithFormat:@"%@", @(slider.value)];
return cell;
}
possibleDrawerDirectionRow++;
});

return cell;
}
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"Bounce Open";
switch (section) {
case MSBounceSectionTypeBounce:
return @"Bounce Open in Direction";
case MSBounceSectionTypeBounceMagnitude:
return @"Bounce Magnitude";
case MSBounceSectionTypeBounceElasticity:
return @"Bounce Elasticity";
}
return nil;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return @"Invoke the 'bouncePaneOpenInDirection:' method to bounce the pane view open to reveal the drawer view underneath.\n\nA bounce can be used to indicate that there's a drawer view controller underneath that can be accessed by swiping, similar to the iOS lock screen camera bounce.";
switch (section) {
case MSBounceSectionTypeBounce:
return @"Invoke the 'bouncePaneOpenInDirection:' method to bounce the pane view open to reveal the drawer view underneath.\n\nA bounce can be used to indicate that there's a drawer view controller underneath that can be accessed by swiping, similar to the iOS lock screen camera bounce.";
}
return nil;
}

#pragma mark - UITableViewDelegate
Expand All @@ -120,4 +201,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
});
}

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
return (indexPath.section == MSBounceSectionTypeBounce);
}

@end

0 comments on commit f6098ba

Please sign in to comment.