Landscape mode and locationInView in opengl es - iphone

So today I implement landscape mode for my app. It is an opengl es application. I rotated it 90 degrees. The first thing I notice is that the touches no longer work. The reason being is that the call to locationInView is still giving the coordinates as though the application is in portrait mode.
How do people typically deal with this? Do I have to write my own version of locationInView to take into account the orientation of the phone? Or is there a better way?

That's default behavior. Whether the iPhone is in portrait or landscape the screen coordinates don't change, so you'll need to adjust for that in your app.

Basically two approaches, each with their own drawbacks/assets.
You could attach your GLview to a viewcontroller and let it handle rotation events and translating window coordinates into "view" coordinates. This is the easiest method, but your drawing performance could be compromised.
Manage the rotation yourself. You'll need to add your own methods for dealing with the rotations, driven by the UIDeviceOrientationDidChangeNotification notification. This method should include the GL commands to rotate the matrix, translate touches, etc..

Related

How to handle UIImagePickerController overlay rotation in landscape?

You cannot subclass UIImagePickerController, but surely there is clean(not saying obvious or easy) way to keep camera feed as background of UIViewController and just make UIImagePickerController overlay to rotate like it would respond to shouldAutorotateToInterfaceOrientation: ?
I just want to UIImagePicker stay in its beloved portrait orientation, but I want rotate my UI buttons that I put into camera overlay. What I have now, is changing each element's orientation with CGAffineTransformMakeRotation() so it always stays at the same place, but rotates around each center.
I downloaded Layar app and the somehow achieved it... camera feed stays and UI buttons rotates (like UIViewController's style).
edit: I have to use iOS 5.1 and Xcode 4.2
edit2: for now I have this int DIRECTION and depending on what is the current orientation of the device I assign from 0 to 3, so I can decide with what angle to rotate all UI buttons. I do this inside shouldAutorotateToInterfaceOrientation: which is returning only YES for portrait and upside portrait.
You have to put constraints on the buttons and picker view.
Use this link to study AutoLayout concept by Ray Wenderlich
Hope this will help but you have to go through it thoroughly.

Rotating camera view on iOS

I've read few questions here on stack and I'm in a dead-end. I want to have device (iPhone/iPad) camera as a background, to one of my ViewControllers. I'm using Storyboard and UINavigationsViewController, so I'm modyfing a child ViewController. As far as I read, this means that I cannot force this "child" to start in specific orientation (first problem).
Secondly, I decided to go with UIImagePickerController, but as I got it right - you cannot rotate this component, right?
So basically my question is where to go from here, to achieve camera view on background no matter what device orientation? It surely can be done, because Vuforia i.e. has it (and they are using UIImagePickerController with EAGLView).
You have two options to do that task:
1) You can use Eaglview to render the frames of camera device in background.
2) You can use caeagllayer to do the same.
To draw on that layer you have to use drawableproperties and CaTransformationMatrix

Get Orientation without autorotation in Cocos2d Project

I have a small issue and I can't find any solution. How can I turn off autorotation for views and ogl and still get Orientation?
For example if I set GAME_AUTOROTATION to kGameAutorotationNone the notification center UIApplicationDidChangeStatusBarOrientationNotification doesn't work.
If I allow in shouldAutorotateToInterfaceOrientation two orientations autorotation appear again. If I implement a blank willRotateToInterfaceOrientation nothing change.
So, how can I get orientations change without actually rotate anything?
Thanks in advance.
You can manage your own orientation method by rotating your Current CCLayer/CCScene. on willRotateToInterfaceOrientation method. But make sure, you will get WRONG touch pixels on all 3 touch events..! You have to modify the touch-cordinates according to your orientation them before taking them in calculations.

Flip the iPhone screen with a button

how do I implement a button that will flip the screen 180deg for my game (if the user wishes to play it with the iPhone upside-down), and have it affect all of my 5 different views?
You should apply a transform to the parent view (your UIWindow). The rotation can be made using CGAffineTransformMakeRotation().
It might be better to actually allow the device orientation to cause the rotation though. In App settings set that the app supports autorotation and then in the UIViewController return tru to -(BOOL)shouldAutorotateToInterfaceOrientation when the rotation passed in is UIInterfaceOrientationPortraitUpsideDown
Look at shouldAutorotateToInterfaceOrientation. And maybe [myView setNeedsDisplay]; could help.
It sounds like you just want to use the build in automatic orientation rotation. You may need to tell your app in the build settings that it supports the upsidedown orientation and as dasdom mentioned you need to implement shouldAutorotateToInterfaceOrientation in all of your view controllers.
There is no way to force the phone into an orientation on-demand.
If you are looking to just rotate a view you can apply a CGAffineTransform.

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