2016-01-29 61 views
0

我使用uiscrollview,當我在scrollview中單擊按鈕時,我在textView中添加文本,然後在視圖外按鈕,所以...當按鈕在外部視圖中向下滾動並且無法單擊按鈕。我的代碼:SWIFT:在uiscrollview中不能按下按鈕

變化滾動視圖高度:

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 1000); 

enter image description here

+0

檢查滾動視圖內的所有視圖的自動調整。你的按鈕是可見的,但實際上它不是。並確保您的按鈕有用戶交互YES。檢查你的按鈕是否可見。看到我的答案如下 –

+0

可能重複的[UIButton在UIScrollView中不起作用](http://stackoverflow.com/questions/16649639/uibutton-does-not-work-when-它功能於UIScrollView中) – shpasta

回答

0
CGRect frameforMainView = mainView.frame; 
frameforMainView.size.height = viewFirstAnswerButton.frame.origin.y + viewFirstAnswerButton.frame.size.height; 
mainView.frame = frameforMainView; 

//Now Set ContentSize Of scroll view; 
[scrollView setContentSize:CGSizeMake(0, mainView.frame.origin.y + mainView.frame.size.height)]; 

如果您正在使用自動版式然後不要忘記添加translatesAutoresizingMaskIntoConstraints = YES

1

你可以嘗試設置delaysContentTouches到您的UIScrollView上的false

UIScrollView

0

在我的情況下,當按鈕進入子視圖 - >成滾動型,水龍頭不被緩存,不無論什麼滾動你的視圖設置..

所以我增加了按鈕作爲我的scrollView的子視圖並點擊被觸發

scrollView.addSubview(button) 
0

將所有子視圖從mainView拖動到ScrollView。並隱藏mainView。確保mainView(scrollView的ContainerView)也應該是scrollView的子視圖。

相關問題