質問

これは初心者の質問に聞こえるかもしれませんが、私はiOS開発者に慣れていません、

iPadビューでuiwebviewとuitableviewを使用しています。の shouldAutorotateToInterfaceOrientation 私はそれらのように見えるようにそれらをサイズ変更します。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {    
        if( interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
            CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2);
            self.mTextView.frame = f;
            f = CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2);
            self.mTableView.frame = f;
        }
        if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {     
            CGRect f = CGRectMake(0, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
            self.mTextView.frame = f;
            f = CGRectMake(self.view.frame.size.width / 2, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
            self.mTableView.frame = f;        
        }   
        return YES;
    }

質問:最初のロードのために、テーブルビューは正しいサイズで描画されますが、ポートレートモードに切り替えると、ランドスケープモードに戻ると、uableビューはフレームで指定されているよりも広くなります。では、なぜこれが起こるのか、そしてこれを修正する方法は?

詩また、同じ方法ですべてのセルのフレームを設定しようとしました。

PSS。これはデバイスでのみ発生し、シミュレータでuitableviewが正しく表示されます

役に立ちましたか?

解決

shouldAutorotateToInterfaceOrientation: ビューコントローラーが指定された方向をサポートするかどうかを示すブール値のみを返します。この方法でUI変換を行うべきではありません。 willAnimateRotationToInterfaceOrientation:duration:.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{    
    if( interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2);
        self.mTextView.frame = f;
        f = CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2);
        self.mTableView.frame = f;
    }
    if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {     
        CGRect f = CGRectMake(0, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
        self.mTextView.frame = f;
        f = CGRectMake(self.view.frame.size.width / 2, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
        self.mTableView.frame = f;        
    }
}

uiviewcontrollerのドキュメントをご覧ください, 、それはよく説明されています。

他のヒント

iOSはこの関数を一度に呼び出します!あなたが期待するようにこの作業をうまく行うには、この行をに追加する必要があります (void)viewDidLoad 関数:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

そして作る (void)orientationChanged:(id)object 関数:

- (void)orientationChanged:(id)object{
    UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication] statusBarOrientation;

    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
        // some works
    }else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){
        // another works
    }
}

それがあなたに役立つことを願っています!

ポートレートモードとランドスケープモードの両方で、uitableviewのサイズを変更できます。 UableViewの変更サイズは、以前の方向モードに関する比率で自動的に変更されます。そのため、両方のモードの希望のサイズを修正できます。

この仕事をあなたのために願っています。

確認してください autoResizing ビューの財産。

最も簡単な方法は、ポートレートモードとランドスケープモードの2つの異なるビューを作成できることです。そのため、モードが変更されるたびにビューを簡単に変更できます。このような:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        self.view = self.portraitView;
    else 
        self.view = self.landscapeView;
    [tblScore reloadData];
    return YES;
}

あなたが使う AutoResizing このために、フレームのコーディングを行う必要はありません。http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/creatingviews/creatingviews.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top