diff --git a/Classes/DialerViewController.h b/Classes/DialerViewController.h index 49e6d857c..0c9437d99 100644 --- a/Classes/DialerViewController.h +++ b/Classes/DialerViewController.h @@ -28,6 +28,8 @@ #import "UIDigitButton.h" @interface DialerViewController : UIViewController { + + CGFloat initialPreviewAngle; } - (void)setAddress:(NSString*)address; diff --git a/Classes/DialerViewController.m b/Classes/DialerViewController.m index a3a399688..86c901839 100644 --- a/Classes/DialerViewController.m +++ b/Classes/DialerViewController.m @@ -135,6 +135,9 @@ static UICompositeViewDescription *compositeDescription = nil; selector:@selector(coreUpdateEvent:) name:kLinphoneCoreUpdate object:nil]; + + initialPreviewAngle = [self orientationToAngleRad:self.interfaceOrientation]; + // Update on show if([LinphoneManager isLcReady]) { LinphoneCore* lc = [LinphoneManager getLc]; @@ -211,26 +214,38 @@ static UICompositeViewDescription *compositeDescription = nil; [super viewDidUnload]; } -- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; - CGRect frame = [videoPreview frame]; - switch (toInterfaceOrientation) { +- (CGFloat)orientationToAngleRad:(UIInterfaceOrientation)orientation { + CGFloat angle=0; + switch (orientation) { case UIInterfaceOrientationPortrait: - [videoPreview setTransform: CGAffineTransformMakeRotation(0)]; + angle = 0; break; case UIInterfaceOrientationPortraitUpsideDown: - [videoPreview setTransform: CGAffineTransformMakeRotation(M_PI)]; + angle = M_PI; break; case UIInterfaceOrientationLandscapeLeft: - [videoPreview setTransform: CGAffineTransformMakeRotation(M_PI / 2)]; + angle = M_PI / 2; break; case UIInterfaceOrientationLandscapeRight: - [videoPreview setTransform: CGAffineTransformMakeRotation(-M_PI / 2)]; + angle = -M_PI / 2; break; default: break; } - [videoPreview setFrame:frame]; + return angle; +} + +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { + UIInterfaceOrientation old = self.interfaceOrientation; + CGFloat angle = 0; + [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; + + if( old != toInterfaceOrientation ){ + CGRect frame = [videoPreview frame]; + angle = [self orientationToAngleRad:toInterfaceOrientation] - initialPreviewAngle; + [videoPreview setTransform: CGAffineTransformMakeRotation(angle)]; + [videoPreview setFrame:frame]; + } }