Skip to content

Commit

Permalink
convert scrollview point to parent bounds, added images
Browse files Browse the repository at this point in the history
  • Loading branch information
rnystrom committed Aug 29, 2013
1 parent 11b3cb8 commit 094415b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
Binary file removed .DS_Store
Binary file not shown.
60 changes: 30 additions & 30 deletions RNFrostedSidebar.m
Original file line number Diff line number Diff line change
Expand Up @@ -353,37 +353,32 @@ - (void)showInViewController:(UIViewController *)controller animated:(BOOL)anima
[self rn_addToParentViewController:controller callingAppearanceMethods:YES];
self.view.frame = controller.view.bounds;

CGFloat parentWidth = self.parentViewController.view.bounds.size.width;
CGRect frame = controller.view.bounds;
frame.origin.x = self.showFromRight ? parentWidth - _width : 0;
frame.size.width = _width;
self.contentView.frame = frame;
CGFloat parentWidth = self.view.bounds.size.width;

CGRect blurFrame = frame;
blurFrame.origin.x = _width;
blurFrame.size.width = 0;
CGRect contentFrame = self.view.bounds;
contentFrame.origin.x = _showFromRight ? parentWidth : -_width;
contentFrame.size.width = _width;
self.contentView.frame = contentFrame;

[self layoutItems];

CGRect blurFrame = CGRectMake(_showFromRight ? self.view.bounds.size.width : 0, 0, 0, self.view.bounds.size.height);

self.blurView = [[UIImageView alloc] initWithImage:blurImage];
self.blurView.frame = blurFrame;
self.blurView.contentMode = self.showFromRight ? UIViewContentModeTopRight : UIViewContentModeTopLeft;
self.blurView.contentMode = _showFromRight ? UIViewContentModeTopRight : UIViewContentModeTopLeft;
self.blurView.clipsToBounds = YES;
[self.view insertSubview:self.blurView belowSubview:self.contentView];

frame = self.view.bounds;
frame.origin.x = self.showFromRight ? self.view.bounds.size.width : -_width;
self.view.frame = frame;

frame.origin.x = 0;
blurFrame.origin.x = self.showFromRight ? parentWidth - _width : 0;
contentFrame.origin.x = _showFromRight ? parentWidth - _width : 0;
blurFrame.origin.x = contentFrame.origin.x;
blurFrame.size.width = _width;

[UIView animateWithDuration:self.animationDuration
delay:0
options:kNilOptions
animations:^{
self.view.frame = frame;
self.contentView.frame = contentFrame;
self.blurView.frame = blurFrame;
}
completion:nil];
Expand Down Expand Up @@ -449,18 +444,19 @@ - (void)dismissAnimated:(BOOL)animated {
};

if (animated) {
CGRect frame = self.view.frame;
frame.origin.x = self.showFromRight ? self.view.bounds.size.width : -_width;
CGFloat parentWidth = self.view.bounds.size.width;
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = self.showFromRight ? parentWidth : -_width;

CGRect blurFrame = self.blurView.frame;
blurFrame.origin.x = _width;
blurFrame.origin.x = self.showFromRight ? parentWidth : 0;
blurFrame.size.width = 0;

[UIView animateWithDuration:self.animationDuration
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.view.frame = frame;
self.contentView.frame = contentFrame;
self.blurView.frame = blurFrame;
}
completion:completion];
Expand Down Expand Up @@ -488,14 +484,7 @@ - (void)handleTap:(UITapGestureRecognizer *)recognizer {
#pragma mark - Private

- (void)didTapItemAtIndex:(NSUInteger)index {
if ([self.delegate respondsToSelector:@selector(sidebar:didTapItemAtIndex:)]) {
[self.delegate sidebar:self didTapItemAtIndex:index];
}

BOOL didEnable = ! [self.selectedIndices containsIndex:index];
if ([self.delegate respondsToSelector:@selector(sidebar:didEnable:itemAtIndex:)]) {
[self.delegate sidebar:self didEnable:didEnable itemAtIndex:index];
}

if (self.borderColors) {
UIColor *stroke = self.borderColors[index];
Expand All @@ -517,17 +506,21 @@ - (void)didTapItemAtIndex:(NSUInteger)index {
[self.selectedIndices removeIndex:index];
}

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(-CGRectGetMidX(view.bounds), -CGRectGetMidY(view.bounds), view.bounds.size.width, view.bounds.size.height) cornerRadius:view.layer.cornerRadius];
CGRect pathFrame = CGRectMake(-CGRectGetMidX(view.bounds), -CGRectGetMidY(view.bounds), view.bounds.size.width, view.bounds.size.height);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:pathFrame cornerRadius:view.layer.cornerRadius];

// accounts for left/right offset and contentOffset of scroll view
CGPoint shapePosition = [self.view convertPoint:view.center fromView:self.contentView];

CAShapeLayer *circleShape = [CAShapeLayer layer];
circleShape.path = path.CGPath;
circleShape.position = CGPointMake(CGRectGetMidX(view.frame), CGRectGetMidY(view.frame));
circleShape.position = shapePosition;
circleShape.fillColor = [UIColor clearColor].CGColor;
circleShape.opacity = 0;
circleShape.strokeColor = stroke.CGColor;
circleShape.lineWidth = self.borderWidth;

[self.contentView.layer addSublayer:circleShape];
[self.view.layer addSublayer:circleShape];

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
Expand All @@ -543,6 +536,13 @@ - (void)didTapItemAtIndex:(NSUInteger)index {
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[circleShape addAnimation:animation forKey:nil];
}

if ([self.delegate respondsToSelector:@selector(sidebar:didTapItemAtIndex:)]) {
[self.delegate sidebar:self didTapItemAtIndex:index];
}
if ([self.delegate respondsToSelector:@selector(sidebar:didEnable:itemAtIndex:)]) {
[self.delegate sidebar:self didEnable:didEnable itemAtIndex:index];
}
}

- (void)layoutSubviews {
Expand Down
Binary file not shown.
21 changes: 20 additions & 1 deletion example/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,28 @@ - (void)viewDidLoad {

- (IBAction)onBurger:(id)sender {
NSArray *images = @[
[UIImage imageNamed:@"gear"],
[UIImage imageNamed:@"globe"],
[UIImage imageNamed:@"profile"],
[UIImage imageNamed:@"star"],
[UIImage imageNamed:@"gear"],
[UIImage imageNamed:@"globe"],
[UIImage imageNamed:@"profile"],
[UIImage imageNamed:@"star"],
[UIImage imageNamed:@"gear"],
[UIImage imageNamed:@"globe"],
[UIImage imageNamed:@"profile"],
[UIImage imageNamed:@"star"],
];
NSArray *colors = @[
[UIColor colorWithRed:240/255.f green:159/255.f blue:254/255.f alpha:1],
[UIColor colorWithRed:255/255.f green:137/255.f blue:167/255.f alpha:1],
[UIColor colorWithRed:126/255.f green:242/255.f blue:195/255.f alpha:1],
[UIColor colorWithRed:119/255.f green:152/255.f blue:255/255.f alpha:1],
[UIColor colorWithRed:240/255.f green:159/255.f blue:254/255.f alpha:1],
[UIColor colorWithRed:255/255.f green:137/255.f blue:167/255.f alpha:1],
[UIColor colorWithRed:126/255.f green:242/255.f blue:195/255.f alpha:1],
[UIColor colorWithRed:119/255.f green:152/255.f blue:255/255.f alpha:1],
[UIColor colorWithRed:240/255.f green:159/255.f blue:254/255.f alpha:1],
[UIColor colorWithRed:255/255.f green:137/255.f blue:167/255.f alpha:1],
[UIColor colorWithRed:126/255.f green:242/255.f blue:195/255.f alpha:1],
Expand All @@ -36,14 +52,17 @@ - (IBAction)onBurger:(id)sender {

RNFrostedSidebar *callout = [[RNFrostedSidebar alloc] initWithImages:images selectedIndices:self.optionIndices borderColors:colors];
callout.delegate = self;
// callout.showFromRight = YES;
[callout show];
}

#pragma mark - RNFrostedSidebarDelegate

- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
NSLog(@"Tapped item at index %i",index);
// [sidebar dismiss];
if (index == 3) {
[sidebar dismiss];
}
}

- (void)sidebar:(RNFrostedSidebar *)sidebar didEnable:(BOOL)itemEnabled itemAtIndex:(NSUInteger)index {
Expand Down
Binary file added images/click.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/open.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 094415b

Please sign in to comment.