I'm using a custom movie player in my application, its working fine.
But I'm stuck up with managing the rotation of the player, I want to rotate the player as the phone rotates, similar to the default nature of mpmovie player.
How can I control that?
Do the view controllers in the hierarchy above it support auto-rotation? By default, only portrait orientation is supported, but you can override shouldAutorotateToInterfaceOrientation: to specify others.
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.
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
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.
I'm using cocos2d and i want to play a movie. For these purposes i've created MPMoviePlayerViewController and put it as a subview to [[CCDirector sharedDirector] openGLView]. The problem is that it appears in a vertical orientation.
In the application orientation is set to landscape:
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
How can i change the orientation of my player ?
Have a look at the cocos2d manual page about autorotation:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:autorotation
Basically you have to decide between two solutions:
Cocos2D handles orientation changes and you need to rotate the MPMoviePlayerViewController's view manually (e.g. using CGAffineTransformMakeRotation).
Cocos2D's opengl-view doesn't handle orientation changes and is inside a UIViewController that overrides shouldAutorotateToInterfaceOrientation and thus automatically rotates the view for you.
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..