【发布时间】:2015-06-11 23:22:57
【问题描述】:
我有一个向笔尖添加子视图的 iOS 项目。子视图的内容使用自动布局设置为中心,但是当子视图添加到滚动视图时,子视图的内容不在中心。 代码如下:
UIView *scroller = [[[NSBundle mainBundle] loadNibNamed:@"scroller" owner:self options:nil] objectAtIndex:0];
[self.view addSubview:scroller];
CGSize size = self.view.bounds.size;
NSLog(@"view size: %f", size.width);
self.scrollView.contentSize = CGSizeMake(size.width, size.height);
self.scrollView.frame = CGRectMake(0, 0, size.width, size.height);
self.myView.frame = CGRectMake(0, 0, size.width, size.height);
self.scrollView.bounds = self.myView.bounds;
[self.scrollView addSubview:self.myView];
下面是输出的样子: http://imgur.com/h6cejTA
我还上传了我的项目: http://www.filedropper.com/myproject
【问题讨论】:
-
自动布局规范在哪里?
self.myView是什么?为什么要设置滚动视图bounds?这与scroller有何关系? -
self.scrollView.bounds = self.myView.bounds;的原因是什么? -
self.myView 是我试图在滚动视图中显示的视图。它被加载在称为“滚动条”的笔尖中。我设置了滚动视图边界,因为我认为它可以解决我的问题。如果我没有边界,视图仍然加载偏离中心。
-
滚动条内有 2 个视图。一个只是一个带有滚动视图的视图。另一个是带有图像、标签和文本字段的视图
标签: ios objective-c uiview uiscrollview