From 909a62b696bd9639071a9986c7d6875e10502e9b Mon Sep 17 00:00:00 2001 From: Kirill Zhdanovich Date: Wed, 10 Jul 2013 18:01:23 +0300 Subject: [PATCH] [iOS] Compass heading fix --- iphone/Maps/Bookmarks/BookmarksVC.mm | 5 ----- iphone/Maps/Classes/MapViewController.mm | 1 - iphone/Maps/Classes/MapsAppDelegate.mm | 1 + iphone/Maps/Classes/PlaceAndCompasView.mm | 5 ----- iphone/Maps/Classes/SearchVC.mm | 5 ----- iphone/Maps/Platform/LocationManager.h | 2 +- iphone/Maps/Platform/LocationManager.mm | 12 +++++++----- 7 files changed, 9 insertions(+), 22 deletions(-) diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index 765f3dd3ef..2a64a7de26 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -402,11 +402,6 @@ [super viewWillDisappear:animated]; } -- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation -{ - [m_locationManager setOrientation:self.interfaceOrientation]; -} - - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField.text.length == 0) diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index d897fe43ce..28c097bd9e 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -529,7 +529,6 @@ NSInteger compareAddress(id l, id r, void * context) - (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation { - [[MapsAppDelegate theApp].m_locationManager setOrientation:self.interfaceOrientation]; [self showPopover]; [self Invalidate]; } diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 3d49c96d5e..0a66f95245 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -57,6 +57,7 @@ void InitLocalizedStrings() - (void) applicationWillEnterForeground: (UIApplication *) application { + [m_locationManager orientationChanged]; [m_mapViewController OnEnterForeground]; } diff --git a/iphone/Maps/Classes/PlaceAndCompasView.mm b/iphone/Maps/Classes/PlaceAndCompasView.mm index 482de7a4cf..90ff009783 100644 --- a/iphone/Maps/Classes/PlaceAndCompasView.mm +++ b/iphone/Maps/Classes/PlaceAndCompasView.mm @@ -256,11 +256,6 @@ return [text sizeWithFont:font constrainedToSize:CGSizeMake([self getCurrentSuperViewWidth] - 2 * MARGIN, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping].height + 2 * SMALLMARGIN; } -- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation -{ - [m_locationManager setOrientation:(CLDeviceOrientation)fromInterfaceOrientation]; -} - -(CGFloat) countHeight { if ([self.secondaryInfo length]) diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index 2dd07bf608..e714cc78b2 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -312,11 +312,6 @@ static void OnSearchResultCallback(search::Results const & res) numberOfRowsInEmptySearch = 0; } -- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation -{ - [m_locationManager setOrientation:self.interfaceOrientation]; -} - - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; // All orientations are supported. diff --git a/iphone/Maps/Platform/LocationManager.h b/iphone/Maps/Platform/LocationManager.h index d761ecc7be..9fdfd1204a 100644 --- a/iphone/Maps/Platform/LocationManager.h +++ b/iphone/Maps/Platform/LocationManager.h @@ -29,7 +29,7 @@ - (CLLocation *)lastLocation; - (CLHeading *)lastHeading; // Fixes compass angle orientation when rotating screen to landscape -- (void)setOrientation:(UIInterfaceOrientation)orientation; +- (void)orientationChanged; - (bool)getLat:(double &)lat Lon:(double &)lon; - (bool)getNorthRad:(double &)rad; diff --git a/iphone/Maps/Platform/LocationManager.mm b/iphone/Maps/Platform/LocationManager.mm index 23815f23e0..a0f464e9e8 100644 --- a/iphone/Maps/Platform/LocationManager.mm +++ b/iphone/Maps/Platform/LocationManager.mm @@ -24,6 +24,7 @@ m_lastLocationTime = nil; m_isCourse = NO; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil]; } return self; } @@ -33,6 +34,7 @@ [m_observers release]; [m_locationManager release]; [m_lastLocationTime release]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @@ -202,11 +204,6 @@ return YES; } -- (void)setOrientation:(UIInterfaceOrientation)orientation -{ - m_locationManager.headingOrientation = (CLDeviceOrientation)orientation; -} - - (bool)getLat:(double &)lat Lon:(double &)lon { CLLocation * l = [self lastLocation]; @@ -251,4 +248,9 @@ return (([self lastLocation] != nil) && ([m_lastLocationTime timeIntervalSinceNow] > -300.0)); } +-(void)orientationChanged +{ + m_locationManager.headingOrientation = (CLDeviceOrientation)[UIDevice currentDevice].orientation; +} + @end