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
Related
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.
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.
In augmented reality app,on Camera view another transparent view will be, On this transparent view, we used for drawing on camera view and saving it, can you suggest (Start and end) me how to work with this application,
thanks you, have a great day
You'll want to use a UIImagePickerController to show the camera preview. Set its showsCameraControls property to no, so none of the standard photo-taking interface is visible. Now, UIImagePickerControllers have a nice little cameraOverlayView property that you can use to place any view you want over the camera preview. Depending on what precisely you want to augment your reality with, this view could be realized in different ways. For example, if you want to overlay 3D models over the camera preview, this view could be a transparent OpenGL ES context. If you don't need any 3D assets, it can be a regular transparent UIView on which you draw some custom graphics with Quartz. It's up to you, but you want the general pattern of:
UIImagePickerController with showsCameraControls = NO
set cameraOverlayView to some transparent view to render content
This is really a huge question, and there are tons of intricacies depending on the specifics of your design. This is just a general summary.
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.
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..