5

1 のストーリーボードがあり、ネストされた多数の s を含むUIViewController1 を保持しています。View Controller をサブクラス化して、このメソッドを実装しました。UIViewUIView

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

私も追加しました

<key>UISupportedInterfaceOrientations</key>
    <array>
     <string>UIInterfaceOrientationLandscapeLeft</string>
     <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeLeft</string>

Info.plist

メイン UIView の viewDidLoad で、私はこれをやっています:

PASectionView* sectionView = [[PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 180)];
[self addSubview:sectionView];

問題は、コントロールの幅が予想される 1024 ピクセルではなく 756 ピクセルしかないことです。詳細については、以下のスクリーンショットを参照してください。ここに画像の説明を入力私はウェブ全体を検索してきましたが、このイライラする問題の解決策がどこにも見つかりません。基本SDKとして設定されたiOS5.1でXcode 4.5を使用しています。

編集 フレームを境界に置き換えることで機能しています。ただし、何が起こっているのか理解できないため、フレームサイズでは機能しません。

4

4 に答える 4

11

スーパービューの座標系でのビューの位置とサイズを表すフレーム四角形。

@property(nonatomic) CGRect フレーム

独自の座標系でのビューの位置とサイズを表す境界の四角形。

@property(nonatomic) CGRect 境界

フレームではなく境界を使用します。

于 2012-07-09T12:37:30.337 に答える
2

autoresizingMask回転時に自動サイズ変更するビューに設定します。このような:

[myView setAutoresizingMask:UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleRightMargin];
于 2012-07-09T12:36:45.303 に答える
0

問題は、ランドスケープモードにロードする前に、コード行がメソッドloadingを呼び出しているためです。[PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 180)]; [self addSubview:sectionView];これは、ビューコントローラクラスの場合はどのメソッドを呼び出しているのか[PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)]; [self addSubview:sectionView];、そのサブクラスのUIView場合はどこでViewDidLoadメソッドを取得したのかを示す必要があります。クラスでの問題を解決するには、次のようにし.hます。このPASectionView*sectionViewを記述します。.mクラスでこのメソッドを実装します

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{

}
else  // OrientationLandscape
{
sectionView.frame = CGRect(sectionView.frame.origin.x,sectionView.frame.origin.y,self.view.frame.size.width,180);    
}
于 2012-07-09T12:37:00.340 に答える
0

サブビューの自動サイズ変更マスクを設定する必要があります。

subView がコードで追加されている場合は、subView をスーパービューに追加する前に、このコード行を追加します。yourSubView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

サブビューがnibファイルに追加されている場合は、nibファイルのサブビューのプロパティで境界マグネットとサイズ変更マスクを選択します。

于 2012-07-09T12:39:31.037 に答える