3
我有一个视图控制器,在其中包含UIScrollView的横向模式下启动。我尝试创建子视图并将它们添加到UIScrollView,但视图的框架大小均为纵向大小。在横向模式下向UIScrollView添加子视图
这里是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight)];
NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
for (int i = 0; i < colors.count; i++)
{
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * i;
frame.origin.y = 0;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[self.scrollView addSubview:subview];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count,
self.scrollView.frame.size.height);
self.scrollView.pagingEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.scrollsToTop = NO;
}
输出:
可能的重复的这个答案:[LandscapeOrientation开始在目标c中的didload方法](http://stackoverflow.com/questions/8775911/landscapeorientation-on-start-of-didload-method-in-objective-c ) – Pfitz 2012-01-08 10:31:21
通过对准上旋转的子视图修正问题如在建议[在寻呼清洁自转跃迁的UIScrollView] [1] [1]:http://stackoverflow.com/questions/3322554/clean-自动旋转 - 在分页-uiscrollview中转换 – Eric 2012-01-09 07:37:05
当您旋转设备时,您需要更改滚动视图尺寸 – Dhara 2013-05-16 09:09:23