From 5574cedaea8ec6a296c778fbb6344eb030807959 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Tue, 30 Sep 2014 15:56:34 +0200 Subject: [PATCH] Fix landscape start discrepancies on iPad for iOS8. --- Classes/ChatRoomViewController.m | 5 +- .../LinphoneUI/UICompositeViewController.h | 1 + .../LinphoneUI/UICompositeViewController.m | 122 +++++++++--------- Classes/MainStoryboard.storyboard | 2 +- Classes/WizardViewController.m | 3 +- 5 files changed, 67 insertions(+), 66 deletions(-) diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index aaadf0902..e6b251115 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -790,12 +790,13 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [UIView setAnimationCurve:curve]; [UIView setAnimationBeginsFromCurrentState:TRUE]; - if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { + if(([[UIDevice currentDevice].systemVersion floatValue] < 8) && + UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { int width = endFrame.size.height; endFrame.size.height = endFrame.size.width; endFrame.size.width = width; } - + // Resize chat view { CGRect viewFrame = [[self view] frame]; diff --git a/Classes/LinphoneUI/UICompositeViewController.h b/Classes/LinphoneUI/UICompositeViewController.h index faef77352..9a227c6b6 100644 --- a/Classes/LinphoneUI/UICompositeViewController.h +++ b/Classes/LinphoneUI/UICompositeViewController.h @@ -71,6 +71,7 @@ - (void)setFullScreen:(BOOL) enabled; - (void)setStateBarHidden:(BOOL) hidden; - (void)setToolBarHidden:(BOOL) hidden; +- (BOOL)currentViewSupportsLandscape; - (UIViewController *)getCachedController:(NSString*)name; - (UIViewController *)getCurrentViewController; - (UIInterfaceOrientation)currentOrientation; diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index 97e29d9aa..6cc84de74 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -165,13 +165,31 @@ #pragma mark - ViewController Functions +- (void)updateViewsFramesAccordingToLaunchOrientation { + CGRect frame = [self.view frame]; // this view has the correct size at launch (1024/768 for iPad, 320*{568,480} for iPhone) + UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; + BOOL portrait = UIInterfaceOrientationIsPortrait(orientation); + CGRect oppositeFrame = frame; + oppositeFrame.size.height = frame.size.width; + oppositeFrame.size.width = frame.size.height; + + // if we start in portrait, the landscape view must get the opposite height and width + if( portrait || [[UIDevice currentDevice].systemName floatValue] < 8 ){ + Linphone_log(@"landscape get opposite: %@", NSStringFromCGSize(oppositeFrame.size)); + [landscapeView setFrame:oppositeFrame]; + } else { + // if we start in landscape, the landscape view has to get the current size, + // whereas the portrait has to get the opposite + Linphone_log(@"landscape get frame: %@ and portrait gets opposite: %@", NSStringFromCGSize(frame.size), NSStringFromCGSize(oppositeFrame.size)); + [landscapeView setFrame:frame]; + [portraitView setFrame:oppositeFrame]; + } +} + - (void)viewDidLoad { - /* Force landscape view to match portrait view */ - CGRect frame = [portraitView frame]; - int height = frame.size.width; - frame.size.width = frame.size.height; - frame.size.height = height; - [landscapeView setFrame:frame]; + /* Force landscape view to match portrait view, because portrait view inherits + the device screen size at load */ + [self updateViewsFramesAccordingToLaunchOrientation]; [super viewDidLoad]; } @@ -215,6 +233,8 @@ [self.stateBarViewController viewDidDisappear:animated]; } +#pragma mark - Rotation messages + - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { currentOrientation = toInterfaceOrientation; [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; @@ -224,7 +244,7 @@ } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; + [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; // Will invoke TPMultiLayout [self.contentViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; [self.tabBarViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; [self.stateBarViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; @@ -265,58 +285,27 @@ */ + (void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated { UIView *firstResponder = nil; - for(UIWindow *window in [[UIApplication sharedApplication] windows]) { - if([NSStringFromClass(window.class) isEqualToString:@"UITextEffectsWindow"] || - [NSStringFromClass(window.class) isEqualToString:@"_UIAlertOverlayWindow"] ) { - continue; - } - UIView *view = window; - UIViewController *controller = nil; - CGRect frame = [view frame]; - if([window isKindOfClass:[UILinphoneWindow class]]) { - controller = window.rootViewController; - view = controller.view; - } - UIInterfaceOrientation oldOrientation = controller.interfaceOrientation; - - NSTimeInterval animationDuration = 0.0; - if(animated) { - animationDuration = 0.3f; - } - [controller willRotateToInterfaceOrientation:orientation duration:animationDuration]; - if(animated) { - [UIView beginAnimations:nil context:nil]; - [UIView setAnimationDuration:animationDuration]; - } - switch (orientation) { - case UIInterfaceOrientationPortrait: - [view setTransform: CGAffineTransformMakeRotation(0)]; - break; - case UIInterfaceOrientationPortraitUpsideDown: - [view setTransform: CGAffineTransformMakeRotation(M_PI)]; - break; - case UIInterfaceOrientationLandscapeLeft: - [view setTransform: CGAffineTransformMakeRotation(-M_PI / 2)]; - break; - case UIInterfaceOrientationLandscapeRight: - [view setTransform: CGAffineTransformMakeRotation(M_PI / 2)]; - break; - default: - break; - } - if([window isKindOfClass:[UILinphoneWindow class]]) { - [view setFrame:frame]; - } - [controller willAnimateRotationToInterfaceOrientation:orientation duration:animationDuration]; - if(animated) { - [UIView commitAnimations]; - } - [controller didRotateFromInterfaceOrientation:oldOrientation]; - if(firstResponder == nil) { - firstResponder = [UICompositeViewController findFirstResponder:view]; - } + + UIViewController *controller = nil; + + controller = [[UIApplication sharedApplication] keyWindow].rootViewController; + CGRect frame = [[UIScreen mainScreen] bounds]; + UIInterfaceOrientation oldOrientation = controller.interfaceOrientation; + + NSTimeInterval animationDuration = animated? 0.3f : 0.0; + + [controller willRotateToInterfaceOrientation:orientation duration:animationDuration]; + [controller willAnimateRotationToInterfaceOrientation:orientation duration:animationDuration]; + [controller didRotateFromInterfaceOrientation:oldOrientation]; + [UIView animateWithDuration:animationDuration animations:^{ + [controller.view setFrame:frame]; + }]; + + if(firstResponder == nil) { + firstResponder = [UICompositeViewController findFirstResponder:controller.view]; } - [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:animated]; + + // [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:animated]; if(firstResponder) { [firstResponder resignFirstResponder]; [firstResponder becomeFirstResponder]; @@ -499,8 +488,8 @@ UIViewController *newContentViewController = [self getCachedController:description.content]; UIViewController *newStateBarViewController = [self getCachedController:description.stateBar]; - UIViewController *newTabBarViewController = [self getCachedController:description.tabBar]; - + UIViewController *newTabBarViewController = [self getCachedController:description.tabBar]; + [UICompositeViewController removeSubView: oldContentViewController]; if(oldTabBarViewController != nil && oldTabBarViewController != newTabBarViewController) { [UICompositeViewController removeSubView:oldTabBarViewController]; @@ -508,7 +497,7 @@ if(oldStateBarViewController != nil && oldStateBarViewController != newStateBarViewController) { [UICompositeViewController removeSubView:oldStateBarViewController]; } - + self.stateBarViewController = newStateBarViewController; self.contentViewController = newContentViewController; self.tabBarViewController = newTabBarViewController; @@ -517,6 +506,11 @@ UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; if(currentOrientation != correctOrientation) { [UICompositeViewController setOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown]; + if( UIInterfaceOrientationIsLandscape(correctOrientation) ){ + [self.contentViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:0]; + [self.tabBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:0]; + [self.stateBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:0]; + } } else { if(oldContentViewController != newContentViewController) { UIInterfaceOrientation oldOrientation = self.contentViewController.interfaceOrientation; @@ -536,7 +530,7 @@ [self.stateBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:0]; [self.stateBarViewController didRotateFromInterfaceOrientation:oldOrientation]; } - } + } } else { oldViewDescription = (currentViewDescription != nil)? [currentViewDescription copy]: nil; } @@ -681,4 +675,8 @@ return [[self.contentViewController retain] autorelease]; } +- (BOOL)currentViewSupportsLandscape { + return currentViewDescription ? currentViewDescription.landscapeMode : FALSE; +} + @end diff --git a/Classes/MainStoryboard.storyboard b/Classes/MainStoryboard.storyboard index ab978559e..9bff85a03 100644 --- a/Classes/MainStoryboard.storyboard +++ b/Classes/MainStoryboard.storyboard @@ -24,7 +24,7 @@ - + diff --git a/Classes/WizardViewController.m b/Classes/WizardViewController.m index 0609bf960..268800a29 100644 --- a/Classes/WizardViewController.m +++ b/Classes/WizardViewController.m @@ -917,7 +917,8 @@ static UICompositeViewDescription *compositeDescription = nil; [UIView setAnimationCurve:curve]; [UIView setAnimationBeginsFromCurrentState:TRUE]; - if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { + if(([[UIDevice currentDevice].systemVersion floatValue] < 8) && + UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { int width = endFrame.size.height; endFrame.size.height = endFrame.size.width; endFrame.size.width = width;