Reputation: 5076
I'm working on a photo view controller to display some photos in portrait and landscape view as well. What I did is edit the -(BOOL)shouldAutorotateToInterfaceOrientation
orientation with the code below but when testing in xcode (menu hardware > Rotate right) the view does not rotate in landscape. Any thing wrong in what I did ?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
The view controller is a part of a tab based iphone app and this view is not root view: is this the problem ?
Upvotes: 4
Views: 2296
Reputation: 63
I'm not sure it's a type error or edition difference, in my latest Xcode the method is like this:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
and it works well, are you missing the "to" of the argument?
Upvotes: 0
Reputation: 676
this could be just a typo, but its not UIIinterfaceOrientation
, its UIInterfaceOrientation
Upvotes: 1
Reputation: 3045
Your looking in the wrong place: in your RootViewController.m
file look for the following code:
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
//lots of useless comments
//
return (UIInterfaceOrientationIsPortrait(interfaceOrientation) ); //THIS LINE HERE
the line that says return (UIInterface... Portrait) is the line that determines your app's rotating capabilities. You can change this to whatever to allow you to be able to rotate completely, keep it at a certain orientation, or whatever you desire...
also in this
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIIinterfaceOrientation)interfaceOrientation
{
/* return (interfaceOrientation == UIIinterfaceOrientationPortrait || interfaceOrientation == UIIinterfaceOrientationLandscapeLeft || interfaceOrientation == UIIinterfaceOrientationLandscapeRight); */ //GET RID OF ALL THIS CRAP
return true; //do this instead, and if this doesn't work, try return YES;
}
Upvotes: 0
Reputation: 10786
Make sure that the ViewController in which you implement this method, is the window's rootViewController.
Also, using return (interfaceOrientation != UIIinterfaceOrientationPortraitUpsideDown)
is nicer to read. ;)
Does -shouldAutorotateToInterfaceOrientation get called at all? Try logging something in this method...
Upvotes: 0
Reputation: 552
My first idea would be to just return true;
to make sure there's no issue with the parameters being passed in / your comparison (it looks good to me but you never know).
Next would be, if this view is not directly attached to the window (or other top-level object if you're using xib's) you may have to also return true in any parent views. For the sake of testing you might just want to overwrite:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIIinterfaceOrientation)interfaceOrientation
{
return true;
}
for all view (controllers) in the tree.
Upvotes: 1
Reputation: 1824
Also check your supported Orientations. For XCode 4 (Project->Summary(Tab)->Supported Device Orientation->Desired Orientations).
Upvotes: 1
Reputation: 75396
The method you want to override is shouldAutorotateToInterfaceOrientation
. Your method signature is missing the Orientation
on the end.
Upvotes: 0