Autoresizing views on iPhone
I am currently working on a project and I need to support both portrait and landscape orientation. I have read several books, and all of them tell me to do different things. The view I want to support landscape orientation is simple. It is a UINavigationBar and a UIWebview which is attached to the viewcontrollers view. I have made the view programatically.
Is it correct that I use this method:
- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;I have seen that prior to iOS 3 there was two other methods that were invoked. However I do not target my app below iOS 3.
This code is working but my question is if it is the correct way of doing it programmatically because I don't want to use the InterfaceBuilder on this view.
Codesnippet (working)
- (void)willAnimateRotationToInterfaceOrie开发者_JAVA百科ntation:(UIInterfaceOrientation)x duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(x)) {
topbar.frame = CGRectMake(0.0f, 0.0f, 480.0f, 44.0f);
}
}
And is it correct that I don't need to apply any animation, iOS will handle this right?
You can use the below two methods to support interface orientations
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
//Set the boolean variable for interface orientation condition.
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
//Set the coordinates of the Views you are using.
}
Yes you do not have to worry about the animation part,the OS will take care of it.
The Method you are using is for Custom Changes to the User Interface. You have to do the Animation there yourself. (That's why there is a Duration param) If you just have your 2 Views which need to resize, you can set the Autoresizing mask.
i.e.:
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
精彩评论