2

XCODE 4.5にアップグレードして以来、この問題に直面しています。

さまざまなUI要素があります

UIButton *button1; UIButton *button2; UIButton *button3;

- (void)viewDidLoad
 {
    button1 =[[UIButton alloc]init ];
    button1.backgroundColor=[UIColor yellowColor];
[self.view addSubview:button1];


button2 =[[UIButton alloc]init ];
button2.backgroundColor=[UIColor yellowColor];
[self.view  addSubview:button2];


button3 =[[UIButton alloc]init ];
button3.backgroundColor=[UIColor yellowColor];
[self.view  addSubview:button3];
}

フレームが宣言されている

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {  
 if(interfaceOrientation==UIInterfaceOrientationPortrait ||[interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown )
 {


 button1.frame=CGRectMake(10,10,10,10);
 button2.frame=CGRectMake(10,30,10,10);

 button3.frame=CGRectMake(10,50,10,10);
 }
      if(interfaceOrientation ==UIInterfaceOrientationLandscapeLeft ||interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
 button1.frame=CGRectMake(20,10,10,10);
 button2.frame=CGRectMake(20,30,10,10);

 button3.frame=CGRectMake(20,50,10,10);
  }

 return YES;

}

ただし、フレームは Xcode 4.5 では設定されていません。以前のバージョンでは正常に機能していました。

アプリで自動サイズ調整がひどく必要です。だから私を助けて。

4

2 に答える 2

4

オリエンテーションのために、viewControllerに新しいメソッド(「ios6」で導入)を実装する必要があります

- (BOOL)shouldAutorotate
{

    return TRUE;

}

- (NSUInteger)supportedInterfaceOrientations
{
     return UIInterfaceOrientationMaskAll;


}

そして、コードを変更して、以下のメソッド内にコードを配置します

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
{

 }  

また、ウィンドウを確認してください。以下のようにaddSubviewではなく、rootviewControllerとしてウィンドウにコントローラーを追加する必要があります。

self.window.rootViewController = viewController;

于 2012-09-25T12:09:25.143 に答える
1

一部のクラスは、デバイスの向きがポートレートからランドスケープに変更されると自動的にサイズ変更されますが、他のクラス(UILabelやUITextViewなど)では少し設定が必要です。

setAutoresizesSubviewsプロパティは、境界が変更されたときに各オブジェクトのサイズを自動的に変更するかどうかを制御します。

setAutoresizingMaskプロパティは、各オブジェクトのサイズを自動的に変更する方法を制御しますUILabelは幅のサイズ変更のみを気にする必要がありますが、UITextViewはスクロール可能であるため、境界が変更されたときに幅と高さの両方のサイズを変更する必要があります。

また、 shouldAutorotateToInterfaceOrientationメソッドがYESを返すように構成されていることを確認する必要があります。そうしないと、デバイスの向きが変わってもビューは何もしません。

サンプルコード:

[self.myLabel setAutoresizesSubviews:YES];
[self.myLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

[self.myTextView setAutoresizesSubviews:YES];
[self.myTextView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

詳細については、こちらをご覧 ください

于 2012-09-25T12:10:19.060 に答える