[英]iOS 7 - UIScrollView subView not showing
Trying to add subviews to UIScrollView, which is defined in XIB file. 尝试将子视图添加到XScroll文件中定义的UIScrollView。 The code below is how I tried to add subviews in my view controller.
下面的代码是我尝试在视图控制器中添加子视图的方式。 But no subviews were added.
但未添加任何子视图。
Any suggestions? 有什么建议么?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
CGRect frame = _tasksScrollView.frame;
frame.size.width /= 3.0;
NSArray *colors = [NSArray arrayWithObjects:[UIColor blueColor],
[UIColor redColor],
[UIColor yellowColor],
[UIColor greenColor],
[UIColor purpleColor],
nil];
for (int i = 0; i < [colors count]; i++, frame.origin.x += frame.size.width) {
UIView *subView = [[UIView alloc] initWithFrame:frame];
subView.backgroundColor = [colors objectAtIndex:i];
[_tasksScrollView addSubview:subView];
}
_tasksScrollView.contentSize = CGSizeMake(frame.size.width * [colors count], frame.size.height);
}
It may be that your subviews are offset relative to the view space in your scroll view since youre carrying over the x
and y
coordinates from the scrollview.frame
itself which is actually a position relative to the full screen. 子视图可能相对于滚动视图中的视图空间偏移,因为您继承了
scrollview.frame
本身的x
和y
坐标,而这实际上是相对于全屏的位置。 Try setting the x
and y
position of the subview so that it starts from 0
. 尝试设置子视图的
x
和y
位置,使其从0
开始。
造成这种情况发生的原因有很多,在大多数情况下,您只是无法链接/连接XIB中的IBOutlet属性(_tasksScrollView)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.