iPad Orientation Lock Notification? - iphone

Is there a way to receive a notification when the iPad gets orientation locked? When the orientation lock is set on or off, it does send a receivedRotate: notification, but I need a way to be able to distinguish normal rotations from lock "rotations".
The problem is I am rotating things in my view when the rotation changes. When the lock is activated, the iPad sends a receivedRotate: with UIInterfaceOrientationPortrait.
I've looked in UIDevice for something like isOrientationLocked, but with no success.
Thanks for any clues on this.
EDIT: When the iPad orientation lock is switched ON, it does send a notification that the rotation changed to portrait for some reason. This causes the elements to rotate since they rotate with any orientation change. This is what I want to prevent.
EDIT2: Yes, the iPad shouldn't send a portrait notification but it does. After this portrait notification the iPad stops sending notifications, which is the way it should be. It's just the initial notification that is in the way.
I cannot use the accelerometer because I still want to be able to use the orientation lock's locking feature. Maybe I would use the accelerometer if I had some way of knowing when the iPad was locked.
EDIT3: receivedRotate: is called with UIInterfaceOrientationPortrait for all orientations.

Apparently it's working now.
I recently jumped back into my old project after installing the latest XCode & iPhone SDK and I no longer receive UIInterfaceOrientationPortrait when the lock is switched on. Haven't changed my code at all so it must be Apple.

Just to be clear, are you only using the rotation notifications to determine your rotations? You are not pulling data from the accelerometer or the like to get your orientation?
One other thing is that the lock is just that, a lock, it should not force you into portrait mode if you are in landscape. It should just keep you in landscape.
So, guessing from what you are doing I might suggest that you really do not want to be using the notifications as the basis of your interface but rather the accelerometer data directly.
As a newly minted iPad owner I might wonder what you are doing since I see the lock as a way to keep the orientation the way I want when my physical orientation is not "normal" like laying on the couch.

Related

Play video on landscape and force app return to portrait

I used MPMoviePlayerViewController to play a video and when back to app, I need app force return portrait
I think the best way to solve this is by using
https://stackoverflow.com/a/13800907/620197
These are callbacks who only gets called when the user autorotates - you can tell the user to rotate the device and then the autorotate callback will be called and will show only the supported orientation.
If you still want force rotation i believe you need to dismiss the controller - try this and please do tell me if it worked out for you:
IOS 6 force device orientation to landscape
I have searched the web for a long time for a force rotation solution that will please me with no success, it almost looks like apple
Doesnt want us to be able to so this.

Will iAds be loaded, if I hide the ADBannerView?

I know Apple recommends just placing the adview offscreen,
incase there is an error, loading an iAd,
but I would like to hide it using [adView setHidden: YES];.
If I do so, will the view check for new ads available?
In the simulator sure it will load the Test Ads,
but will it also work after releasing the app onto actual devices from the AppStore?
SideSwipe
Yes, it should work on real device.

How to change orientation of iPhone on button click?

I've been searching through lots of posts trying to find a way to change the orientation of the view manually. However I can't seem to find a definitive answer that's not outdated. Please can someone suggest the best way to switch the orientation based on when a user presses a button?
I.e. I need some help filling in the gap...
- (IBAction)buttonPressed:(id)sender
{
// Switch the orientation to ...
}
The Apple guideline doesn't allow that. There's some hack to do that but it's not a good idea to use it.
Your app will run in a real device and there isn't any piece of code that can physically turn the phone. Device orientation is constraint by real world constraint, you can't force your user to turn his phone.
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft
Change the orientation to Landscape or Portrait.
You might have to also apply a transformation to complete the change:
self.view.transform = CGAffineTransformRotate(self.view.transform, -(M_PI / 2.0));

UIDevice Orientation

How to find out if the UIDeviceOrientationFaceUp is landscape FaceUp or Portrait FaceUp?
Can any one tell me?
UIDeviceOrientation will only tell you the orientation of the physical device. You need to use methods that use UIInterfaceOrientation (from UIApplication) to make decisions depending on whether the screen is in portrait and landscape mode.
You can use UIInterfaceOrientationIsLandscape() and UIInterfaceOrientationIsPortrait() with a UIInterfaceOrientation too.
I realise this is an old question now, but looking at the answers everyone is being overly pedantic. In case anyone else stumbles across this:
The answer to your problem is for you to keep a secondary variable which is any of your accepted orientations.
When the device orientation notification comes in, simply look at the incoming orientation and see if its an acceptable one, (portrait/landscape NOT faceup/facedown) then update your secondary variable, and finally trigger a ui/app refresh from there using your secondary variable as the orientation source.
This will have the effect of locking the orientation to the "last known good" orientation.
It's not possible, because the accelerometer can't detect rotation around the z axis. On an iPhone 4, you could perhaps use the gyroscope for this (using CoreMotion), but UIDevice doesn't have an API for this. You would then also have to define what the starting position is, because you can't detect in which direction the user is from the device's point of view.
UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown are orientations for when the device is laying flat (like on a table). Portrait and Landscape don't make sense in this cases.
There is no way you can find out from orientation . I have found a workaround.
CGRect screenBounds = [[UIScreen mainScreen]bounds];
if(screenBounds.size.width > screenBounds.size.height)
{
// This means FaceUP/Down is in Landscape
}
else
{
// This means FaceUp/Down is in Portrait
}

iPhone Video Rotationn

I'm using the UIIMagePickerController for video capture but after the capture I publish it on our servers and it turns out that the video is not properly oriented. But this problem only occurs when the user take's video in Portrait mode in LandScape Mode everything is simply fine.
Is there any way in which I can detect in which mode video was captured and How can i rotate the video before publish so that everything works fine.
Well, you can query the UIDevice for #property UIDeviceOrientation orientation, and let the server know if the video was captured in landscape or portrait.
You can use one of the helpful UIDeviceOrientationIsLandscape macro to do this.
To query for current orientation, just do
[UIDevice currentDevice].orientation
but watch out: (from UIDevice documentation) The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.