How to detect Camera Overlay view rotation - iphone

I'm trying to make a camera overlay view on top of the camera accomodate according to the screen orientation. Since even if you lock your screen orientation on the settings, the camera still rotates its UI (the flash and camera buttons that are on the live preview), if I don't move the elements I have on the overlay view, it stays on top of those.
I already accomplished this by registering to the UIDeviceOrientationDidChangeNotification notification, and then reading the value on [UIDevice currentDevice].orientation and setting the transform value of my camera overlay view.
The problem with this is the UIDeviceOrientationDidChangeNotification notification doesn't fire when the user locks the interface on their iPhone (but the camera keeps rotating!).
I've tried a number of alternatives, like registering to the PLCameraDeviceOrientationChangedNotification notification that I found being fired when registering myself as an observer for every notification, but it doesn't contain the orientation on the userInfo dictionary.
I also tried setting up a NSTimer to fire every 0.5s and check the [UIDevice currentDevice].orientation, but it always reports UIDeviceOrientationPortrait when it's locked, regardless of the actual device orientation.
Is there any way I can find out the orientation the camera is in, and ideally also be notified when it changes even with the interface orientation locked by the user?
Thanks.

My opinion, it is impossible to get device messages about orientation if user locked it device orientation.
But the accelerometer never lies and should give you the right information.
Juste take a look at :
Detect iPhone screen orientation
EDIT :
here's the apple's sample, for using accelerometer.
https://developer.apple.com/library/ios/#samplecode/AccelerometerGraph/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007410

Related

iPhone rotation and full-screen video

I've encountered a strange issue, which I need help resolving. My app is always run in portrait mode - I explicitly want it to be that way. In one place in the app I have a UIWebView, which works just fine, as expected. This web view is not shown all the time but is dynamically added to the main view and removed based on user actions (i.e. it's only visible when I need it to).
Now, sometimes in this view I may have a youtube video. The WebView simply contains the <iframe> for the youtube embed. When a user clicks on the video preview frame in the webview, a full-screen video viewer is launched to play the video - which is just fine.
However if during the playback the user rotates the phone, the full-screen video player is rotated and the video is played in landscape mode. Now the video is stopped and the user presses "Done" button without rotating the phone back to portrait mode, the video player is closed and the user returns to my app - however now my layout is also rotated! Not just the video view, but the entire layout - with toolbar, navigation controller, etc.
I don't want any rotation! I just want everything in my app to remain in portrait mode! Moreover, now even if the phone is rotated back to portrait, the app stays in landscape mode.
Note that I only tested this in a simulator so far, as I currently don't have a physical phone to test. I created a simple (bad quality!) video (just filmed the simulator on my screen with an old phone camera) to demonstrate the issue - the video is here: http://shchuka.com/hosting/rotation_problem.mp4
Any ideas what I can do about it?
Add this in, or change it:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (UIInterfaceOrientation == UIInterfaceOrientationPortrait);
}
That will prevent all rotation and the app will only work in portrait mode. You can place the return statement within IF statements to allow rotation under certain circumstances.
I sometimes add views to the appDelegate window when I want them to be above everything else, and an annoying side-effect has been that I have to explicitly call my own rotation code as there is no VC as such to deal with it. On the plus side, it might mean that it could be ideal for your needs -
[[[[UIApplication sharedApplication] delegate] window] addSubview:myWebView];
...depending on your app's orientation, etc, before you load the view in the first place, you might need to rotate the webView before displaying it.

iPhone, playing a movie in landscape but return to portrait when movie is complete

Total Objective-C/XCode N00b here but I am attempting something, which I assume is simple. I have an app that is written for the iPhone, I don't allow auto orientation and only have the main interface locked into portrait. When the user plays a video in the app I would like to allow them to auto rotate the device from portrait and watch it in landscape (should they choose to do so, I don't want to force this). Once the user presses "Done", I would like to force them back into portrait (even if they are holding the device in landscape) as the interface is only laid out in that orientation.
I've tried using the MPMoviePlayerController and MPMoviePlayerViewController and I am not sure which will give me the leverage/methods I need. I am basically just looking to allow shouldAutorotateToInterfaceOrientation to return yes only when the MPMoviePlayerController view is visible.
Any help MUCH appreciated. Thanks.
I used this code example and it worked perfectly. I think you'll have to set the orientation in the super class.

Can you tell which image the iPad has displayed at app launch? (or, I'd like to know the orientation if possible)

There are a number of similar questions on this site about discovering the orientation of the device in applicationDidFinishLaunchingWithOptions being problematic, but I've yet to find a working solution. The problem I have is that I am adding a full screen image (identical to the currently chosen Default-XXX.png being displayed by the OS to my main window. I do this in order to have an animation happen from the 'splash screen' to my first view controller's view.
Works great, except the device keeps telling me that it is portrait mode - meaning I can't match the image being displayed consistently, since I have different graphics for each orientation)
My understanding is that all apps default to portrait orientation until a rotation occurs inside the app (usually when presenting a viewController) but I'm not 100% convinced.
You should be able to solve this using a view controller. When the application has finished launching, present a view controller in the window. Override the shouldAutorotate… query so that the controller autorotates to portrait/landscape and when you receive one of the rotation callbacks, update the image in the view accordingly. The controller will start up in portrait, but if the device is in some other orientation, the rotation callback will immediately follow and you will get the correct image.
P.S. You might find the Orientation Zoo project helpful when debugging this.

Manually rotating a UIView in response to orientation change? (Not AutoRotate)

I have an OpenGL view that I would like to manually modify and redraw in response to a device orientation change. How can I accomplish this? If I return YES from shouldAutorotateToInterfaceOrientation:, the system does its stock rotation animation, which I don't want. I just want to get a notification and then adjust my openGL scene to match the new orientation. Is this possible, and if so, how?
Observe the UIDeviceOrientationDidChangeNotification notification

Using accelerometer to detect iPad lock switch trigger?

So for complicated reasons I am managing view rotations myself, and am only implementing UIDeviceOrientationPortrait as the autorotating orientation.
Anyway, when one clicks the screen lock on the iPad, the device will rotate to UIDeviceOrientationPortrait, which will cause my code to rotate, which I do not want to happen. For instance of the user is holding the device in "landscape mode", i.e. I have already manually rotated the UI to landscape mode, and he/she clicks the screen lock, it will rotate the UI to portrait mode, even though the user did not move the device at all.
So somehow I need a way to differentiate between rotations to portrait mode occuring from the screen lock, and those occuring from device rotation. As such, I would like somehow to use the accelerometer to detect whether or not the device was actually 'rotated' or whether the button was clicked.
Thanks!