using the device orientation to implement a modal view controller
Please forgive me a noob question, its my first and i honestly expended a considerable effort searching for my own solution.
I have a project with two view controllers. the main on is a portrait view only and the second (sub) modal view controller is to present in landscape mode only. My goal is to have the orientation of the device alone switch the controllers (and to provide a function call to the modal view controller, passing on certain ivars from the main view controller at the same time) similarly I would like a reorienting to portrait to dismiss the modal view and revert to the starting point.
I imagine this is somewhat how apples own calculator app works? Can anybody give me a clue about the most API 开发者_如何学Ccompliant way to go about this? Thank you so much for your time.
I would very much like to avoid a 'back' or 'done' button on the modal view, and change back and forth with the device orientation only if this is at all possible
Apple has a good explanation and sample code for exactly the thing you want to do. See Creating an Alternate Landscape Interface in the View Controller Programming Guide.
If you have rotation enabled for your views then in -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
You can check the orientation and the act accordingly like this:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
//check if modal viewController is already alive
//pop the modal if needed
}
else
{
//destory the modal if its still alive
}
}
精彩评论