Skip to content
Merged
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
3 changes: 3 additions & 0 deletions APParallaxHeader/UIScrollView+APParallaxHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@interface UIScrollView (APParallaxHeader)

- (void)addParallaxWithImage:(UIImage *)image andHeight:(CGFloat)height andShadow:(BOOL)shadow;
- (void)addParallaxWithImage:(UIImage *)image andHeight:(CGFloat)height;
- (void)addParallaxWithView:(UIView*)view andHeight:(CGFloat)height;

Expand All @@ -29,6 +30,8 @@ typedef NSUInteger APParallaxTrackingState;

@interface APParallaxView : UIView

- (id)initWithFrame:(CGRect)frame andShadow:(BOOL)shadow;

@property (nonatomic, readonly) APParallaxTrackingState state;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIView *currentSubView;
Expand Down
16 changes: 11 additions & 5 deletions APParallaxHeader/UIScrollView+APParallaxHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ @interface APParallaxView ()
@implementation UIScrollView (APParallaxHeader)

- (void)addParallaxWithImage:(UIImage *)image andHeight:(CGFloat)height {
[self addParallaxWithImage:image andHeight:height andShadow:YES];
}

- (void)addParallaxWithImage:(UIImage *)image andHeight:(CGFloat)height andShadow:(BOOL)shadow {
if(self.parallaxView) {
if(self.parallaxView.currentSubView) [self.parallaxView.currentSubView removeFromSuperview];
[self.parallaxView.imageView setImage:image];
}
else
{
APParallaxView *view = [[APParallaxView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, height)];
APParallaxView *view = [[APParallaxView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, height) andShadow:shadow];
[view setClipsToBounds:YES];
[view.imageView setImage:image];

Expand Down Expand Up @@ -167,7 +171,7 @@ - (void)drawRect:(CGRect)rect

@implementation APParallaxView

- (id)initWithFrame:(CGRect)frame {
- (id)initWithFrame:(CGRect)frame andShadow:(BOOL)shadow {
if(self = [super initWithFrame:frame]) {

// default styling values
Expand All @@ -181,9 +185,11 @@ - (id)initWithFrame:(CGRect)frame {
[self.imageView setClipsToBounds:YES];
[self addSubview:self.imageView];

self.shadowView = [[APParallaxShadowView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(frame)-8, CGRectGetWidth(frame), 8)];
[self.shadowView setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[self addSubview:self.shadowView];
if (shadow) {
self.shadowView = [[APParallaxShadowView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(frame)-8, CGRectGetWidth(frame), 8)];
[self.shadowView setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[self addSubview:self.shadowView];
}
}

return self;
Expand Down