Skip to content

Commit

Permalink
FIX: image rotation based on device orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
u10int committed Mar 11, 2014
1 parent 8ef8639 commit 24ec7aa
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions URBMediaFocusViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,9 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
#pragma mark - Orientation Helpers

- (void)deviceOrientationChanged:(NSNotification *)notification {
NSLog(@"device orientation changed");
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (_currentOrientation != orientation) {
_currentOrientation = orientation;
UIInterfaceOrientation deviceOrientation = (UIInterfaceOrientation)[UIDevice currentDevice].orientation;
if (_currentOrientation != deviceOrientation) {
_currentOrientation = deviceOrientation;
[self reposition];
}
}
Expand Down Expand Up @@ -766,7 +765,7 @@ - (void)reposition {
CGFloat n1 = sqrtf(t1.a * t1.a + t1.c * t1.c);
CGFloat n2 = sqrtf(t2.a * t2.a + t2.c * t2.c);
CGFloat rotationDelta = acosf(dot / (n1 * n2));
BOOL isDoubleRotation = (rotationDelta > M_PI_2);
BOOL isDoubleRotation = (rotationDelta > 1.581);

// use the system rotation duration
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
Expand All @@ -779,11 +778,11 @@ - (void)reposition {
// if we haven't laid out the subviews yet, we don't want to animate rotation and position transforms
if (_hasLaidOut) {
[UIView animateWithDuration:duration animations:^{
self.imageView.transform = CGAffineTransformConcat(self.imageView.transform, baseTransform);
self.imageView.transform = CGAffineTransformConcat(CGAffineTransformIdentity, baseTransform);
}];
}
else {
self.imageView.transform = CGAffineTransformConcat(self.imageView.transform, baseTransform);
self.imageView.transform = CGAffineTransformConcat(CGAffineTransformIdentity, baseTransform);
}
}

Expand Down

0 comments on commit 24ec7aa

Please sign in to comment.