简体   繁体   English

即使更大的内容大小,Scrollview也不会滚动

[英]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.

相关问题 即使contentSize大于frame并且在设置内容大小之前添加了子视图,scrollView也不起作用 - scrollView doesn't work even though contentSize is larger than frame and subview is added before setting content size ScrollView contentSize比界限大,但没有滚动 - ScrollView contentSize Larger than Bounds, Yet No Scrolling Scrollview ContentSize - Scrollview ContentSize 为什么我的UItableView不能水平滚动而我将ContentSize设置得更大? - Why my UItableView doesn't scroll horizontally whereas I did set ContentSize larger? 即使我的contentsize小于其框架,我的ScrollView仍在滚动 - My ScrollView is scrolling even when my contentsize is smaller than its frame 有ScrollView.contentSize问题无法在顶部,左侧,右侧正确滚动吗? - Having ScrollView.contentSize issues not able to scroll properly on Top, Left, Right? 使用AutoLayout动态布局scrollview contentSize - Dynamically layout scrollview contentSize with AutoLayout Swift Storyboard - 大于设备屏幕的滚动视图不会滚动 - Swift Storyboard - Scrollview larger than device screen won't scroll 为什么即使没有contentView滚动到滚动视图,scrollview仍然滚动 - Why does scrollview still scroll even when it has no contentView to scroll into UITextView contentSize.height比必要的大吗? - UITextView contentSize.height larger than necessary?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM