UIScrollView没有在方向更改上获得新的大小

d2k*_*agw 7 orientation uiscrollview ipad ios

我有一个非常简单的UIScrollView例子,根本不做它应该做的事情.不确定它是API的错误还是我的代码中的错误.

基本上,我有一个UIViewControllerUIScrollView它的观点.当我将它添加到UIWindow并更改iPad的方向时,我会注销UIScrollViews尺寸,这是错误的(?)报告.

这是我的UIViewController实现:

@implementation CustomViewController
- (void)loadView {
  scrollView = [[[UIScrollView alloc] init] autorelease];
  scrollView.delegate = self;
  scrollView.backgroundColor = [UIColor redColor];
  self.view = scrollView;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  CGSize rect = scrollView.frame.size;
  NSLog(@"will rotate w%f h%f", rect.width, rect.height);
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  CGSize rect = scrollView.frame.size;
  NSLog(@"will animate rotation w%f h%f", rect.width, rect.height);
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
  CGSize rect = scrollView.frame.size;
  NSLog(@"did rotate w%f h%f", rect.width, rect.height);
}

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

@end
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,我在控制台中看到以下条目:

2010-07-11 11:03:05.214 Untitled2[6682:207] will rotate w768.000000 h1004.000000
2010-07-11 11:03:05.214 Untitled2[6682:207] will animate rotation w748.000000 h1024.000000
2010-07-11 11:03:05.619 Untitled2[6682:207] did rotate w748.000000 h1024.000000
2010-07-11 11:03:07.951 Untitled2[6682:207] will rotate w748.000000 h1024.000000
2010-07-11 11:03:07.958 Untitled2[6682:207] will animate rotation w768.000000 h1004.000000
2010-07-11 11:03:08.367 Untitled2[6682:207] did rotate w768.000000 h1004.000000
Run Code Online (Sandbox Code Playgroud)

如您所见,方向更改会调整大小UIScrollView,但仅允许新状态栏.我希望宽度和高度会发生巨大变化,因为宽度和高度UIScrollView都比它高,反之亦然.

有没有办法UIScrollView让它报告它的真实大小?

小智 4

如果你还在寻找的话我有答案。测试边界,而不是框架。

原因:框架是边界和应用于旋转的变换的派生属性。