开发者

ipad SplitView Orientation in DetailView

I am using this code in the DetailView.m of a splitview app. Now the orientation changes occur only when the device is rotated. The detection does not take place when the app is launched. I also get this warning

warning: 'RootViewController开发者_如何学JAVA' may not respond to '-adjustViewsForOrientation:'

What change do I need to make the app adjust the orientation code when the app is launched.

> - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
> duration:(NSTimeInterval)duration {
>     [self adjustViewsForOrientation:toInterfaceOrientation];
> }
> 
> - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
> {
>     if (orientation == UIInterfaceOrientationLandscapeLeft ||
> orientation ==
> UIInterfaceOrientationLandscapeRight)
> {
>         detailDescriptionLabel.center = CGPointMake(235.0f, 42.0f);
>         bigthumbImageView.center = CGPointMake(355.0f, 70.0f);
>         
>     }
>     else if (orientation == UIInterfaceOrientationPortrait ||
> orientation ==
> UIInterfaceOrientationPortraitUpsideDown)
> {
>         detailDescriptionLabel.center = CGPointMake(160.0f, 52.0f);
>         bigthumbImageView.center = CGPointMake(275.0f, 80.0f);
>         
>     } }


To remove the warning, move the definition of -adjustViewsForOrientation: before -willRotateToInterfaceOrientation:….

The -willRotateToInterfaceOrientation:… method will only be called when there's an interface rotation. When the app was first launched, the interface doesn't rotate (it follows the initial orientation), so this call is not generated. You have to call it manually, e.g. in -viewDidLoad:

-(void)viewDidLoad {
   [self adjustViewsForOrientation:self.interfaceOrientation];
}


You need to declare your method in RootViewController.h, like so:

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation;

Otherwise you'll get the warning. To make sure your view rotates when the app launches, add a call to adjustViewsForOrientation in your AppDelegate class in the applicationDidFinishLaunching method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜