簡體   English   中英

使用loadView創建視圖時,視圖的幀大小不會隨輪換而改變

[英]The frame size of the view is not changing on rotation when the view is created with loadView

我有沒有xib的UIViewController,我正在使用loadView構建我的UI,創建並添加兩個滾動視圖。 問題是,當旋轉發生時,主視圖框架大小不會改變。 我的意思是,我在loadView中為主視圖設置初始幀大小(縱向模式:幀大小寬度= 320,高度= 480)。 在旋轉到橫向方向后,視圖主框架尺寸不會改變,並且與縱向模式相同。 這是我的loadView:

-(void)loadView{

  CGRect screenBounds = [[UIScreen mainScreen] bounds];    
  self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height)] autorelease];
  self.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
  self.scrollView1 = [[[UIScrollView alloc] init] autorelease];
  self.scrollView1.frame = CGRectMake...
  [self.view addSubview:self.scrollView1];
  self.scrollView2 = [[[UIScrollView alloc] init] autorelease];
  self.scrollView2.frame = CGRectMake...
  [self.view addSubview:self.scrollView2];

我還為視圖設置了autoresizingMask以擴展或縮小以適應屏幕。 但是在調試控制台時我得到相同的寬度和高度值。 我需要獲得一個新的大小,因為我需要在旋轉發生時重新定位我的兩個scrollViews,例如縮小高度並將scrollViews上的寬度擴展到旋轉到橫向模式。 我可以在shouldRotate中手動完成,只是好奇它應該如何以正確的方式完成。

我注意到self.view.frame大小沒有改變,但self.view.bounds在旋轉時會發生變化,並且bounds表示相對於當前界面方向的正確值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM