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.
Related
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.
I'm looking at how my app will run in Split View on an iPad Pro.
I use constraints for layout, but sometimes I want to know the window orientation in order to tweak the layout by modifying a couple of constraints.
Things are easy to handle if the user rotates the device (I handle the call of viewWillTransitionToSize), but the app has to know its initial orientation.
Until now, I have been using the status bar orientation to determine the device orientation:
UIInterfaceOrientation o = [[UIApplication sharedApplication] statusBarOrientation];
But this doesn't seem to work properly in Split screen mode on the iPad Pro simulator. The problem is that the device is in landscape mode, and the statusbarOrientation call says the app is in landscape mode. But my app is using half the screen, so it needs to do layout as if it's in portrait mode.
If I check the bounds size of myViewController.view, this seems to give the right answer, even if the device has not been rotated. In the bad old days I seem to remember that we couldn't rely on this unless the device had been rotated at least once.
So what's the right way to determine the orientation of my App window in iOS9?
I know this question was asked before, however I need a more specific answer regarding orientation changes,
When i add the view that hides the sensitive data to the app, press the home button, and then change the iPad orientation and go back to the app, the view stays at portrait frame which is not the correct since I changed the orientation and it doesn't cover the entire screen.
Anyone knows how to handle this?
I have the following code in the viewWillAppear function:
CAGradientLayer *bgLayer = [BackgroundLayer yellowGradient];
[bgLayer setBounds:self.view.bounds];
[self.view.layer insertSublayer:bgLayer atIndex:0];
It works perfectly in portrait orientation. However, when the device goes into landscape mode, it produces a white (or default color) background down the side. I have seen other examples of WHY this occurs, but nothing on how to fix it.
What I’m seeing happening is the 1024 resolution on landscape (iPad) dropping to 1004, and I think it’s adjusting it to 0,20 on the x, y.
Has anyone else run into this issue and found how to fix it?
It’s because when you turn the screen sideways, your view, which has a certain background color, does not turn sideways. The view remains in portrait. So you have this portrait-oriented colored view that’s going from the new “top” of the iPad to way below off screen, and on the right side, the view isn’t wide enough to reach, so you just see the app’s default (white) background color.
You can:
apply a CGAffineTransformMakeRotation rotation to your self.view 90º, so that it now displays properly in your now-landscape application,
make your view big enough to cover the entire device, in both landscape and portrait,
make a view with the proper landscape dimensions, and add it when the iPad rotates, or
disable those allowed interface orientations in your Xcode main project file.
Link to CGAffineTransformRotation Demo Code on SO: How to use CGAffineTransformMakeRotation?
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