UIScrollview没有';t滚动iOS
我正在一个视图中创建几个水平滚动的滚动视图。以下代码可以正常工作:UIScrollview没有';t滚动iOS,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,我正在一个视图中创建几个水平滚动的滚动视图。以下代码可以正常工作: -(void)updateSection { builder = [NSMutableArray array]; float xPosition = 0; float xposbut = 100; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, self.frame.size.width, self.fram
-(void)updateSection {
builder = [NSMutableArray array];
float xPosition = 0;
float xposbut = 100;
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, self.frame.size.width, self.frame.size.height - 69)];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.delegate = self;
[self addSubview:scrollView];
for (int i = 1; i < itemArticleArray.count; i++) {
ItemView *item = [ItemView loadNibs];
item.frame = CGRectMake(xposbut, 10, item.frame.size.width, item.frame.size.height);
xPosition += scrollView.frame.size.width + 2;
xposbut += 500;
UIView *seperatorView = [[UIView alloc] initWithFrame:CGRectMake(xposbut - 50, 4, 2, scrollView.frame.size.height - 8)];
[scrollView addSubview:seperatorView];
xPosition += scrollView.frame.size.width + 4;
[scrollView addSubview: item];
[builder addObject:item];
}
[scrollView setContentSize:CGSizeMake(xposbut, scrollView.frame.size.height)];
[self addSubview:scrollView];
}
这会使布局看起来很好,但滚动视图根本不会滚动。有什么想法吗?您可以将
contentSize.height
设置为滚动视图.frame.size.height
,这样滚动视图就不能滚动了。必须将contentSize
设置为scrollView
的总高度,包括不可见区域。框架只是屏幕上的区域。您将contentSize.height
设置为滚动视图.frame.size.height
,因此滚动视图不能滚动。必须将contentSize
设置为scrollView
的总高度,包括不可见区域。框架只是屏幕上的区域。您将contentSize.height
设置为滚动视图.frame.size.height
,因此滚动视图不能滚动。必须将contentSize
设置为scrollView
的总高度,包括不可见区域。框架只是屏幕上的区域。您将contentSize.height
设置为滚动视图.frame.size.height
,因此滚动视图不能滚动。必须将contentSize
设置为scrollView
的总高度,包括不可见区域。框架只是屏幕上的区域。设置滚动视图的内容大小。内容大小应大于frame.size,则只有滚动视图才会滚动。并启用滚动
使用代码
scrollView.scrollEnabled=YES;
scrollView.contentSize=CGSizeMake(CGFloat width, CGFloat height);
高度应大于scrollView.frame.size.Height,并在scrollView框架之外的scrollView中添加内容。设置滚动视图的内容大小。内容大小应大于frame.size,则只有滚动视图才会滚动。并启用滚动
使用代码
scrollView.scrollEnabled=YES;
scrollView.contentSize=CGSizeMake(CGFloat width, CGFloat height);
高度应大于scrollView.frame.size.Height,并在scrollView框架之外的scrollView中添加内容。设置滚动视图的内容大小。内容大小应大于frame.size,则只有滚动视图才会滚动。并启用滚动
使用代码
scrollView.scrollEnabled=YES;
scrollView.contentSize=CGSizeMake(CGFloat width, CGFloat height);
高度应大于scrollView.frame.size.Height,并在scrollView框架之外的scrollView中添加内容。设置滚动视图的内容大小。内容大小应大于frame.size,则只有滚动视图才会滚动。并启用滚动
使用代码
scrollView.scrollEnabled=YES;
scrollView.contentSize=CGSizeMake(CGFloat width, CGFloat height);
高度应大于scrollView.frame.size.Height,并在scrollView框架之外的scrollView中添加内容。UIScrollview将在内容大小大于框架大小时滚动。在代码中,您将内容大小设置为帧大小,这就是为什么您的scrollview不滚动。UIScrollview
将在内容大小大于帧大小时滚动。在代码中,您将内容大小设置为帧大小,这就是为什么您的scrollview不滚动。UIScrollview
将在内容大小大于帧大小时滚动。在代码中,您将内容大小设置为帧大小,这就是为什么您的scrollview不滚动。UIScrollview
将在内容大小大于帧大小时滚动。在您的代码中,您将内容大小设置为帧大小,这就是为什么您的scrollview不滚动的原因。您必须给滚动一些空间来工作,因此请检查以下内容:
在故事板中创建滚动条
为卷轴创建一个出口
在.m
文件中,必须粘贴这些行
守则:
(void)viewDidLoad {
[super viewDidLoad];
yourScroll.scrollEnabled=YES;
yourScroll.contentSize=CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*2);
}
/*
* yourScroll.contentSize=CGSizeMake(your desired scroll width, your desired scroll height);
* The values must be bigger than the viewController size
*/
您必须为滚动条留出一些工作空间,因此请查看以下内容:
在故事板中创建滚动条
为卷轴创建一个出口
在.m
文件中,必须粘贴这些行
守则:
(void)viewDidLoad {
[super viewDidLoad];
yourScroll.scrollEnabled=YES;
yourScroll.contentSize=CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*2);
}
/*
* yourScroll.contentSize=CGSizeMake(your desired scroll width, your desired scroll height);
* The values must be bigger than the viewController size
*/
您必须为滚动条留出一些工作空间,因此请查看以下内容:
在故事板中创建滚动条
为卷轴创建一个出口
在.m
文件中,必须粘贴这些行
守则:
(void)viewDidLoad {
[super viewDidLoad];
yourScroll.scrollEnabled=YES;
yourScroll.contentSize=CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*2);
}
/*
* yourScroll.contentSize=CGSizeMake(your desired scroll width, your desired scroll height);
* The values must be bigger than the viewController size
*/
您必须为滚动条留出一些工作空间,因此请查看以下内容:
在故事板中创建滚动条
为卷轴创建一个出口
在.m
文件中,必须粘贴这些行
守则:
(void)viewDidLoad {
[super viewDidLoad];
yourScroll.scrollEnabled=YES;
yourScroll.contentSize=CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*2);
}
/*
* yourScroll.contentSize=CGSizeMake(your desired scroll width, your desired scroll height);
* The values must be bigger than the viewController size
*/
您更改了哪一行代码?对不起,我已经编辑了上面的帖子,至少有一个contentSize
维度必须大于scrollView
自身的大小才能滚动到某个地方。@AdamAltinkaya:您使用的是iPhone还是iPad。设置滚动视图的背景色,并检查其是否正确position@rokjarc-我只是改变y坐标?你改变了哪行代码?对不起,我现在已经编辑了上面的帖子,至少有一个contentSize
维度必须大于scrollView
自身的大小,才能滚动到某个地方。@AdamAltinkaya:你在使用iPhone还是iPad。设置滚动视图的背景色,并检查其是否正确position@rokjarc-我只是改变y坐标?你改变了哪行代码?对不起,我现在已经编辑了上面的帖子,至少有一个contentSize
维度必须大于scrollView
自身的大小,才能滚动到某个地方。@AdamAltinkaya:你在使用iPhone还是iPad。设置滚动视图的背景色,并检查其是否正确position@rokjarc-我只是改变y坐标?你改变了哪行代码?对不起,我现在已经编辑了上面的帖子,至少有一个contentSize
维度必须大于scrollView
自身的大小,才能滚动到某个地方。@AdamAltinkaya:你在使用iPhone还是iPad。设置滚动视图的背景色,并检查其是否正确position@rokjarc-我只是在改变y坐标