Flip the iPhone screen with a button - iphone

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.

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.

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.

UiViewController rotation question

I have main menu in my app supporting only landscape mode.
I implement landscape restriction by setting up UIRootViewController::shouldAutorotateToInterfaceOrientation:...
And I have another scene with portrait mode support.
So the problem appears when I pass from another scene to main menu in portrait mode: the app doesn't rotate to landscape automatically, and I can't find a code method to manually rotate it.
Is there a solution? Would be thankful.
Edit: Excuse me, I forgot to add details. RootViewController is common for menu and another scene. And what is more - these scenes are in one common view (my app uses OpenGL)
So before I enter menu from portrait scene I set UIRootViewController::shouldAutorotateToInterfaceOrientation: to return YES for landscape only.
If your other scene with portrait support is controlled by another UIViewController, then you can use that view controller's -shouldAutorotateToInterfaceOrientation: to define its behavior. In many cases, this alone should be enough. Of course, if you need to do some fancy rotations for some view controller but not for others, then things get a bit trickier.
There is no easy way to do this, except [UIDevice setOrientation:], which is not open to developers, and leads to application rejection by Apple.
You can apply a rotation to your layer which will create the exact same effect.
myview.layer.transform = CATransform3DMakeRotation(M_PI/2, 0.0f, 0.0f, 1.0f);

Iphone sdk custom uiview orientation issue

I am using custom based uiview controller with uitabbar contains uitableview. I am using image for cell background. I want to do orientation from portrait to landscape but the issue is it is not changing on orientation. I just want to know is there are any special thing for custom uiviewcontroller for orientation?
Thanks in advance
Regards,
sathish
If nothing happens when you rotate the device, you either have the system-wide rotation lock enabled (you checked that, right?), or your view controller isn't returning YES to the alternate orientation in its shouldAutorotateToInterfaceOrientation:, or you're doing something odd with your views that means your view controller isn't getting set as the “frontmost” one and thus isn't getting asked about orientation changes. It'll be easier to narrow that down if you post the code you're using to set up the controller and its view.

Force portrait orientation on pushing new view to UINavigationViewController

I have a TabBar bases application, which supports Landscape orientation only for one special view (the rootview of a UINaviagtionController). Now i want to force portrait orientation for all other views for this navigationcontroller.
I have tried to use
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
This works great but this piece of code is a private api call and I can not risk a app rejection.
I have also tried to rotate the next view manually but this rotates only the view and not the navigation or the tab bar.
Is there a similary way to force orientation change?
There is currently no way to do that.
Have a look at this question, I have the same problems. With a tabbar application, you must have everything to autorotate, or nothing. You can find ways to have shouldAutorotate answer differently on each view, but actually this does not work. I don't know if this is an intended behaviour or a bug, anyway the only viable solution I'm aware of (without using undocumented API) is to manage the rotation by yourself, and do not rely on autorotation.
This means in other words that you need to start orientation notifications (look at UIDevice, there are methods to start and stop notifications about the device orientation), then for each view you want to rotate register as observer, and manage orientation manually, like this (don't remember where I got this snippet):
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
self.view.transform = transform;