stop uiview rotation - iphone

I have a tableview and detail view app, in the tableview I have this to stop it from being able to rotate.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return false;
}
so the main view should always be in portrait mode.
however the subview is able to change rotation freely.. if i go from the detail view while in landscape view to the parent tableview then the tableview appears in landscape and cannot rotate back.. hoping someone can help me fix this.

You're telling it never to rotate, what you actually want is:
return (interfaceOrientation == UIInterfaceOrientationPortrait)
which says it should only rotate when it's to portrait orientation.

Related

UIView in landscape and portrait

I have a UIScrollView with some views in it, everything looks fine in portrait. However when I rotate to landscape all the views are jammed up. Basically what I want is to keep the views in place but then I would be able to scroll on it up and down. How do I deal with this?
Either you support just portrait orientation like this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
or you relayout your views by overriding this method
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
if you've designed your view in Interface Builder, you should pay attention to the Autosizing options in the Size Inspector!
Autosizing

Portrait within Landscape

I am using the interface builder in Xcode 4. I have created a 480(w)x320(h) image to use in landscape mode for my app. WIthin IB I set the view's orientation to "landscape". I place my image on the view. I have set the "supported device orientation" to landscape letf/right. I have changed the info.plist to support landscape orientations.
Here's the weird part: When I run the app, the simulator does rotate/start in landscape, however, my image has somehow rotated 90 degrees as well so it appears cropped and and only takes up about 1/3 of the screen.
So to simplify the explanation, the image always appears in the opposite rotation of the view. I have tried removiong the .png file and re-adding and performing a "clean" with no luck. ANy advice?
you shoukd to modify your shouldAutorotateToInterfaceOrientation metho in all your viewControllers, that should be in landscape:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
}

textfield animation in iPad rotation

I'm starting to upgrading a iPhone App to Universal App, and I have a question: when the user rotates the iPad, how can I animate a couple of textfields?
In portrait, they are at the middle of the view, but in landscape, I want them in the right side of the view.
How can I do that animated?
Thanks,
Rui
When the interface is rotating, your view controller's willAnimateRotationToInterfaceOrientation:duration: method will be called. It is called from inside the animation block for the rotation, so changes to any animatable properties should automatically be animated. The implementation should probably look something like this:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
// Move views to the correct positions for landscape orientation
} else {
// Move views to the correct positions for portrait orientation
}
}

How to stop rotation on `willRotateToInterfaceOrientation:`

I need a way to force the orientation back to portrait on rotate.
The problem is that I have a Tab bar controller, but only want one of the tabs to autorotate.
So I have allowed rotation on all tabs and now I need a way to intercept a rotation on a tab where I don't want to allow rotation.
I'm guessing I can do this on - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration?
Thanks
Tom
There is no way to force rotation. In case of a UITabBarController you are out of luck. It is an all or nothing situation wrt interface rotation. If one of your tabs cannot rotate then the whole UITabBarController stays in portrait mode fixed.
Maybe this would even work if implemented in all your viewControllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (return ([[self.tabBarController.selectedViewController class] isSubclassOfClass:[TurnableViewController class]]) || UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
This will, however, not turn back your view if you switch back to a non-turnable, until you tilt your device...

iPhone: How to Prevent Views From Rotating to Landscape View?

I need to block rotation to landscape orientation because my app crashes when it attempts to rotate views to landscape.
How do I block rotation to landscape and where can I setup the block such that it applies to all my views?
Thanks
In your view controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation==UIInterfaceOrientationPortrait ) {
return YES;
} else {
return NO;
}
}
This will prevent your views from trying to rotate to landscape or upsidedown-portrait. However, this should be default. If you haven't set up code to handle landscape orientation then the views shouldn't be trying to rotate anyway. Your crashing is most likely coming from somewhere else.