滚动视图内容大小应根据方向调整



我的代码是[scrllView setContentSize:CGSizeMake(self.view.bounds.size.width, 1000)];,使其宽度显示在整个屏幕上。但是当我把方向改为横向时,它的宽度没有调整。我认为它不工作,因为我在viewDidLoad方法中这样做,所以它只会计算一次宽度。但是这个的可能解是什么呢? scrLlView应调整宽度

try this

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
{
 //change sub view of scrollview accordingly to orientation
 if(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
     yourScrollView.frame = CGRectMake(0,0,320,460);
     yourScrollView.contentSize = CGSizeMake(320,460);//change accordingly
 else
     yourScrollView.frame = CGRectMake(0,0,480,300);
     yourScrollView.contentSize = CGSizeMake(480,500); //change accordingly
 return YES;
}
[yourScrollView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleHeight];

附加参考

最新更新