UIScrollview未滚动我做错了什么
我有一个问题,我正在向UIViewController添加UIScrolview,但我的UIScrollview不想滚动。我希望它的工作方式与在UITableViewController上的工作方式相同 这里我初始化了我的UIScrollviewUIScrollview未滚动我做错了什么,uiscrollview,Uiscrollview,我有一个问题,我正在向UIViewController添加UIScrolview,但我的UIScrollview不想滚动。我希望它的工作方式与在UITableViewController上的工作方式相同 这里我初始化了我的UIScrollview UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)]; scroll.contentSize = CGSizeMake(320, 8
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)];
scroll.contentSize = CGSizeMake(320, 800);
scroll.backgroundColor = [UIColor redColor];
scroll.showsHorizontalScrollIndicator = YES;
scroll.scrollEnabled = YES;
scroll.userInteractionEnabled=YES;
[self.view addSubview:scroll];
在这里,我将我的内容添加到scrollview:
UILabel *memberNo = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
memberNo.text = @"Member No";
memberNo.font = [UIFont boldSystemFontOfSize:16];
memberNo.textColor = [UIColor limeColor];
[scroll addSubview:memberNo];
memberText = [[UITextField alloc] initWithFrame:CGRectMake(10, 40, 300, 30)];
memberText.placeholder = @"Member No";
memberText.borderStyle = UITextBorderStyleRoundedRect;
memberText.text = @"1111111";
[scroll addSubview:memberText];
内容大小与scrollview相同:没有可滚动的内容
scrollview需要包含一个大于其自身大小的视图。尝试将
contentSize
设置为大于框架。例如:
scroll.contentSize = CGSizeMake(1000, 800);
如果这不起作用,请检查您在哪里设置内容大小。您在哪里初始化
UIScrollView
?尝试将上面的行移动到视图将出现
或视图显示布局子视图
,正如其他人所说,滚动视图的大小(特别是它的边界。大小
)必须小于它的内容大小
,才能真正滚动
您可能希望滚动视图适合其superview,因此请尝试将其边框设置为superview的边界:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
试试这个
将内容大小设置为大于屏幕大小,它将滚动显示是否有更多内容
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)];
水平滚动
scroll.contentSize = CGSizeMake(320, 900);
scroll.contentSize = CGSizeMake(340, 800);
垂直滚动
scroll.contentSize = CGSizeMake(320, 900);
scroll.contentSize = CGSizeMake(340, 800);
滚动视图的帧指滚动视图本身的大小,而内容大小指将在滚动视图中显示的视图的大小。如果要在滚动视图中显示的视图大小小于滚动视图的帧大小,则它根本不会滚动,但如果您将内容大小设置得更大,则滚动视图必须滚动以显示大于其自身帧大小的“额外”大小。 e、 g.如果滚动视图的高度为100,并且您已将内容大小中的高度因子设置为150,则这些额外的50像素将可滚动
祝你好运 我需要做什么才能使它可滚动?如果可能的话,你能提供一个代码示例吗?正如我在回答中所说,内容需要大于scrollview。设置内容大小大于屏幕大小,它将滚动是否有更多内容。