簡體   English   中英

即使更大的內容大小,Scrollview也不會滾動

[英]Scrollview will not scroll even with larger contentsize

有一個奇怪的問題,我不明白。

我將內容大小設置為我創建的名為newSize的CGSize。 我在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);

NSLog打印出768。在界面生成器的滾動視圖中啟用了滾動,但是我無法滾動滾動視圖? 可能是什么問題?

這可能會有所幫助:在提供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];

我解決了這個問題。 這是一個自動布局的復選框,需要在視圖中取消勾選。

可能的問題是框架的寬度等於contentSize的寬度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM