How to rotate iOS MKMapView so that it north-oriented when switching tracking mode? - ios

I am working on an iPad app (iOS 5.1), and I use MKMapView to display a map in my app.
I am switching between the three different map orientation modes using MKUserTrackingModeNone, MKUserTrackingModeFollow, MKUserTrackingModeFollowWithHeading and this works.
However I have a problem with the orientation of the map not resetting to north-facing orientation (north on the map being at the top of the screen) when switching from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeNone.
On the built-in maps app on the ipad, the flow is like this:
When you start the app it is in mode MKUserTrackingModeNone and is north-oriented
When you toggle the orientation mode it changes to MKUserTrackingModeFollow, and the orientation is still north.
When you switch again, it changes to MKUserTrackingModeFollowWithHeading, and the map rotates according to the direction you are facing/pointing the iPad.
When you switch orientation again, it goes back to MKUserTrackingModeNone, and the map nicely rotates back to being north-oriented.
I would like my app to behave in the same way in regards to orientation when switching mode, but when I do as in step 4 above and switch from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeNone, the orientation stays as it was just before making the orientation switch instead of rotating back to north orientation.
I am making the orientation switch with the standard MKUserTrackingBarButtonItem control placed in a toolbar.
Any ideas of how to solve this?
Thanks!

Are you using the standard iOS button bar item for doing this? My app does and as soon as I tap it from followWithHeading to non it rotates back to north is up.

This is a quick fix that works, though it's not very elegant:
https://stackoverflow.com/a/16576802/2077435

Related

How to detect device rotation despite locked display orientation?

So I have an app that needs to not use autorotate. Instead of rotating the screen the buttons on the screen are just supposed to rotate.
I have the interface locked in landscape left. How do I detect what rotation the buttons should be?
I am using a custom opengl engine so I can set the rotation of objects.
You can get the device orientation from:
UIDevice.orientation
This is not the interface orientation, so you get two more possible values for face up and face down. Also the landscape left and right are swapped compared to UIInterfaceOrientation.
You can listen for changes in device orientation by subscribing to the UIDeviceOrientationDidChange notification from NSNotificationCenter. You may have to enable these notifications by calling UIDevice.beginGeneratingDeviceOrientationNotifications().
If the interface orientation is locked on the device, it is not listening to any delegate methods related to orientation changes.

Keep Screen From Turning to Landscape Mode While App Is Running - Swift

I created an app with Swift and tested it out on my iPod touch. The problem is, sometimes I accidentally rotate the screen a little while playing, which throws off everything entirely. Is there a way in Swift to make it so even if the player rotates the device sideways it never turns to landscape mode?
You will want to
Click on the top-left corner (Show the Project Navigator)
Select the name of your project
See what is under General->Deployment Info->Device Orientation.
Adjust the tickboxes accordingly.
Screenshot of Device Orientation in General settings
If you click on your project in top left corner and on the Info tab you can un-tick some of the orientation tick boxes to only allow Portrait.
It's simple.It's not on Swift though.Just swipe up on your ipod and a little tab should come up. Once there,a button with an unlocked lock with an arrow around it.Click it and it should become locked.Now,it won't turn into landscape mode when you turn it! :)

Status bar rotates twice when changing interface orientation

I have an iPad app which supports only Landscape (left and right) orientations. When rotating the device the status bar should rotate together with the interface (180°), but it actually rotates twice (180° + 360°).
Happens only in iOS 8, on lower versions there's no such problem. I was able to reproduce this in Photos app as well. Anyone knows how to work around this?

iOS: Change Orientation only for few pop-up views

I have an app which runs only in Landscape mode. All working well. But I have few pop-up views like Apptentative feedback view and Twitter Sheet view, works great when in portrait mode. So how can I change orientation forcefully when loading these pop-ups and back to landscape when these pop-up closes.
You can't force an orientation change. You can only support changes in orientation. IE moving the device 90 degrees to the right.

iOS Support Multiple Rotations without Animation

I am recreating the Camera app interface for my iPhone app. When it is rotated on its side, instead of rotating the entire UI, I only rotate the icons, just like the normal camera app does. This has worked just fine, but with iOS 5 the notification center orientation depends on the app's orientation. Since my app technically stays in portrait orientation, you can only access the notification center from the top of the screen, even when held sideways. The default camera app has somehow avoided this problem.
I figured the best way to do this is to silently update the UI to be in a different orientation, but from the user's perspective only the icons update. I've tried to achieve this by returning YES in shouldAutorotateToInterfaceOrientation:, and then setting the transform property to rotate the view in willAnimateRotationToInterfaceOrientation:duration:. This works, except it shows an animation where it moves the newly rotated view to its proper position. How can I achieve this without any visible animation?
The answer is actually very simple. All I had to do was change the statusBarOrientation property on [UIApplication sharedApplication] to whatever UIInterfaceOrientation I wanted.

Resources