3

我有没有 xib 的 UIViewController,我正在使用 loadView 来构建我的 UI,它创建并添加了两个滚动视图。问题是,当旋转发生时,主视图框架的大小并没有改变。我的意思是,我正在为 loadView 中的主视图设置初始帧大小(纵向模式:帧大小宽度 = 320,高度 = 480)。旋转到横向后,视图主框架大小没有变化,与纵向模式相同。这是我的加载视图:

-(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 以扩大或缩小以适应屏幕。但是在控制台中调试时我得到了相同的宽度和高度值。我需要获得一个新的尺寸,因为我需要在旋转发生时重新定位我的两个滚动视图,例如在旋转到横向模式时缩小滚动视图的高度和扩展宽度。我可以在 shouldRotate 中手动完成,只是好奇应该如何以正确的方式完成。

4

1 回答 1

9

我注意到 self.view.frame 的大小不会改变,但 self.view.bounds 会发生旋转,并且边界表示相对于当前界面方向的正确值。

于 2011-10-25T14:27:09.903 回答