[英]Scrollview will not scroll even with larger contentsize
Got a strange problem which I dont understand. 有一个奇怪的问题,我不明白。
I set the content size to a CGSize I created called newSize. 我将内容大小设置为我创建的名为newSize的CGSize。 I am adding buttons in a row in the UIScrollView that goes outside of the frame of the scrollview and changing the content size to match the new width + 400 for insurance.
我在UIScrollView的一行中添加了滚动视图框架之外的按钮,并更改了内容大小以匹配新的宽度+ 400保险。
newSize.width = contentSizeWidth+400;
NSLog(@"newSize width: %f", newSize.width);
[_scrollViewOutlet addSubview:button];
[_scrollViewOutlet setContentSize:newSize];
NSLog(@"scrollviewOutlet Content Width: %f", _scrollViewOutlet.contentSize.width);
the NSLog prints out 768. scrolling is enabled in the scrollview in interface builder but I cannot scroll the scrollview? NSLog打印出768。在界面生成器的滚动视图中启用了滚动,但是我无法滚动滚动视图? What could the problem be?
可能是什么问题?
This may help: add buttons before you provide contentSize. 这可能会有所帮助:在提供contentSize之前添加按钮。
// add all buttons
// create contentSizeWidth presumably by adding all buttons height
contentSizeWidth = contentSizeWidth + buttonHeight;// repeat this for every button
[_scrollViewOutlet addSubview:button];
// create newSize
newSize.width = contentSizeWidth+400;
// set content size
[_scrollViewOutlet setContentSize:newSize];
I resolved the issue. 我解决了这个问题。 It was an autolayout tick box that needed unticking in the view.
这是一个自动布局的复选框,需要在视图中取消勾选。
可能的问题是框架的宽度等于contentSize的宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.