Skip to content

Instantly share code, notes, and snippets.

@zapsleep
Created July 29, 2013 08:28
Show Gist options
  • Save zapsleep/6102923 to your computer and use it in GitHub Desktop.
Save zapsleep/6102923 to your computer and use it in GitHub Desktop.
Setters and Getters of DVParallaxView (w/o gyro)
#pragma mark - Getters
-(UIImageView *)backgroundImageView {
if (!_backgroundImageView) {
_backgroundImageView = [[UIImageView alloc] init];
_backgroundImageView.contentMode = UIViewContentModeCenter;
_backgroundImageView.center = CGPointMake(CGRectGetMidX(self.bounds),
CGRectGetMidY(self.bounds));
}
return _backgroundImageView;
}
#pragma mark - Setters
-(void)setParallaxDistanceFactor:(float)parallaxDistanceFactor {
_parallaxDistanceFactor = MAX(0.f, parallaxDistanceFactor);
}
-(void)setParallaxFrontFactor:(float)parallaxFrontFactor {
_parallaxFrontFactor = MAX(0.f, parallaxFrontFactor);
}
-(void)setBackgroundImage:(UIImage *)backgroundImage {
_backgroundImage = backgroundImage;
[self.backgroundImageView setImage:_backgroundImage];
CGPoint origin = CGPointMake(CGRectGetMidX(self.bounds) - backgroundImage.size.width/2.f,
CGRectGetMidY(self.bounds) - backgroundImage.size.height/2.f);
self.backgroundImageView.frame = (CGRect){.origin = origin, .size = backgroundImage.size};
}
-(void)setFrontView:(UIView *)frontView {
_frontView = frontView;
[self addSubview:frontView];
}
#pragma mark - Overriding
-(void)addSubview:(UIView *)view {
if (self.frontView)
[super insertSubview:view belowSubview:self.frontView];
else
[super addSubview:view];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment