Created
July 29, 2013 08:28
-
-
Save zapsleep/6102923 to your computer and use it in GitHub Desktop.
Setters and Getters of DVParallaxView (w/o gyro)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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