From 33fe3fdfeeaf149448aeb14ccd9dfd601be13330 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Fri, 23 Nov 2012 10:36:02 +0100 Subject: [PATCH] Rework UICompositeViewController & PhoneMainView dependencies --- .../LinphoneUI/UICompositeViewController.m | 81 ++++++++++++++++++- Classes/PhoneMainView.h | 2 - Classes/PhoneMainView.m | 75 ----------------- 3 files changed, 78 insertions(+), 80 deletions(-) diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index 433987ad1..593f85a82 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -19,7 +19,7 @@ #import "UICompositeViewController.h" -#import "PhoneMainView.h" +#import "LinphoneAppDelegate.h" @implementation UICompositeViewDescription @@ -252,7 +252,7 @@ // Update rotation UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; if(currentOrientation != correctOrientation) { - [PhoneMainView setOrientation:correctOrientation animated:currentOrientation != UIDeviceOrientationUnknown]; + [UICompositeViewController setOrientation:correctOrientation animated:currentOrientation != UIDeviceOrientationUnknown]; } } } @@ -260,6 +260,81 @@ #pragma mark - +/* + Will simulate a device rotation + */ ++ (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]; + } + } + [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:animated]; + if(firstResponder) { + [firstResponder resignFirstResponder]; + [firstResponder becomeFirstResponder]; + } +} + ++ (UIView*)findFirstResponder:(UIView*)view { + if (view.isFirstResponder) { + return view; + } + for (UIView *subView in view.subviews) { + UIView *ret = [UICompositeViewController findFirstResponder:subView]; + if (ret != nil) + return ret; + } + return nil; +} + - (void)clearCache:(NSArray *)exclude { for(NSString *key in [viewControllerCache allKeys]) { bool remove = true; @@ -441,7 +516,7 @@ // Update rotation UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; if(currentOrientation != correctOrientation) { - [PhoneMainView setOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown]; + [UICompositeViewController setOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown]; } else { if(oldContentViewController != newContentViewController) { UIInterfaceOrientation oldOrientation = self.contentViewController.interfaceOrientation; diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index ad679eaea..bd8aaeec7 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -61,8 +61,6 @@ - (void)fullScreen:(BOOL)enabled; - (void)startUp; -+ (void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated; - - (void)addInhibitedEvent:(id)event; - (BOOL)removeInhibitedEvent:(id)event; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 82ff165f4..941a752f2 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -172,81 +172,6 @@ static PhoneMainView* phoneMainViewInstance=nil; return 0; } -+ (UIView*)findFirstResponder:(UIView*)view { - if (view.isFirstResponder) { - return view; - } - for (UIView *subView in view.subviews) { - UIView *ret = [PhoneMainView findFirstResponder:subView]; - if (ret != nil) - return ret; - } - return nil; -} - -/* - Will simulate a device rotation - */ -+ (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 = [PhoneMainView findFirstResponder:view]; - } - } - [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:animated]; - if(firstResponder) { - [firstResponder resignFirstResponder]; - [firstResponder becomeFirstResponder]; - } -} - - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; [mainViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];