Fix Dialer preview not angled correctly at first start if the device is rotated.

This commit is contained in:
Guillaume BIENKOWSKI 2014-01-10 11:09:25 +01:00
parent e7e583cd1d
commit 02ac9da3bd
2 changed files with 26 additions and 9 deletions

View file

@ -28,6 +28,8 @@
#import "UIDigitButton.h"
@interface DialerViewController : UIViewController <UITextFieldDelegate, UICompositeViewDelegate> {
CGFloat initialPreviewAngle;
}
- (void)setAddress:(NSString*)address;

View file

@ -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];
}
}