0

私のアプリにはいくつかのuiViewがあり、両方の向きをサポートするように設定されています。私のuiViewsフレームはiPadの全体のサイズの一部にすぎないので、iPadの向きに応じて、uiviewsフレームを中央に配置しようとしています。これは、viewcontroller.mファイルで次のように実行されます。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    UIInterfaceOrientation des=self.interfaceOrientation;

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) //iPad
    {
        CGRect ScreenBounds  = [[UIScreen mainScreen] bounds];

        if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown)//ipad-portrait
        {

            ipStPosX=(ScreenBounds.size.width -360)/2;
            ipStPosY=100; 
            return YES;
        }
        else//ipad -landscape
        {
            ipStPosX=(ScreenBounds.size.height -360)/2;
            ipStPosY=100; 
            return YES;
        }
    }
    else//iphone
    {
        UIInterfaceOrientation des=self.interfaceOrientation;

        if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown) //iphone portrait
        {
            return NO;
        }
        else //iphone -landscape
        {
            return YES;
        }
    }
}

アプリを起動して向きを変更すると、デバイスの持ち方に関係なく、常に縦向きの部分であるUIInterfaceOrientationPortraitに移動します。

私は、問題に実際には適合せず、混乱したり、日付が付けられていた古い投稿をいくつか見たので、ここでの助けは素晴らしいでしょう。

4

2 に答える 2

1

shouldAutorotateToInterfaceOrientation:特定の向きをサポートしていることをiOSに伝えるためのものです。iPhoneランドスケープ以外のすべてが必要なので、戻る必要があります

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //iPad
        return YES;
    return UIInterfaceOrientationIsPortrait(orientation);
}

for actually adjusting what you display, you want to use willRotateToInterfaceOrientation:duration: or didRotateFromInterfaceOrientation: for actually changing items. in your case, given that you are just adjusting some iVars depending upon which orientation you are in, i presume you will use the latter.

- (void)didRotateToInterfaceOrientation:(UIInterfaceOrientation)fromOrientation
    UIInterfaceOrientation des = self.interfaceOrientation;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //iPad
    {
        CGRect ScreenBounds  = [[UIScreen mainScreen] bounds];

        if (UIInterfaceOrientationIsPortrait(des))//ipad-portrait
        {
            ipStPosX=(ScreenBounds.size.width -360)/2;
            ipStPosY=100; 
        }
        else //ipad -landscape
        {
            ipStPosX=(ScreenBounds.size.height -360)/2;
            ipStPosY=100; 
        }
    }
}
于 2012-07-24T20:43:31.020 に答える
0

I think there are two problems here:

  1. Enabling rotation - This can be done by implementing the method below. You should put a breakpoint in this method to ensure its called and you return YES. Please note that this method is only called for those views that are pushed to the navigation bar or tab bar or are part of the window. This will not be called for views that have been added to other views using addSubView method.

    • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation;
  2. Implementing the above method and not implementing any other method will rotate your view. If it does not, you need to investigate the points I have outlined above. Once your view starts rotating, you need to then play with the autoresizing masks to achieve what you are planning to do. Centering the views should be easily achievable using autoresizing masks. If using XIBs, you can review the resizing behavior from within xcode.

于 2012-07-26T06:38:30.247 に答える