Permalink
Browse files

Merge pull request #4 from krzak/master

Orientation awarness. Interface Builder compatibility. Centered image content.
  • Loading branch information...
2 parents cae80df + 5f0afd5 commit 43b2d69b56aaa18cb533098338747ad9b97f716a @thisandagain committed Jul 30, 2013
Showing with 24 additions and 7 deletions.
  1. +24 −7 DIYParallax/DIYParallax.m
View
@@ -33,17 +33,30 @@ - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
- // Init layers object
- layers = [[NSMutableArray alloc] init];
-
- // Init motion manager
- motionManager = [[CMMotionManager alloc] init];
- motionManager.deviceMotionUpdateInterval = UPDATE_INTERVAL;
+ [self setup];
}
return self;
}
+- (id)initWithCoder:(NSCoder *)aDecoder
+{
+ if (self = [super initWithCoder:aDecoder]) {
+ [self setup];
+ }
+ return self;
+}
+
+- (void) setup
+{
+ // Init layers object
+ layers = [[NSMutableArray alloc] init];
+
+ // Init motion manager
+ motionManager = [[CMMotionManager alloc] init];
+ motionManager.deviceMotionUpdateInterval = UPDATE_INTERVAL;
+}
+
#pragma mark - Public methods
/**
@@ -65,6 +78,7 @@ - (void)addLayer:(CGFloat)depth imageNamed:(NSString *)asset frame:(CGRect)frame
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", bundlePath, asset]];
item.image = image;
+ item.contentMode = UIViewContentModeCenter;
[self insertSubview:item atIndex:[layers count] - 1];
}
@@ -141,7 +155,10 @@ - (void)update:(CGPoint)point
CGFloat y = [self calculateTransformForAngle:point.y withDistance:d];
// Translate
- view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, OFFSET_MULTIPLIER * x, OFFSET_MULTIPLIER * y);
+ if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
+ view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, OFFSET_MULTIPLIER * x, OFFSET_MULTIPLIER * y);
+ else
+ view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, OFFSET_MULTIPLIER * y, OFFSET_MULTIPLIER * x);
}
}

0 comments on commit 43b2d69

Please sign in to comment.