简体   繁体   中英

SWIFT: in uiscrollview can't press button

I use uiscrollview and when I click button in scrollview I add text in textView and then button outside view so... when button outside view I scroll down and can't click the button. My code:

change scrollView height:

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

在此处输入图片说明

You could try setting the delaysContentTouches to false on your UIScrollView.

UIScrollView

In my case, when button is into a subview -> into a ScrollView, the tap will not be cached, non matter what scroll view settings you have..

So I added the button as subview of my scrollView and tap was fired

scrollView.addSubview(button)
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)];

if you are using Autolayouts then don't forget to add translatesAutoresizingMaskIntoConstraints = YES

Drag all subviews from mainView to ScrollView. And hide the mainView. Make sure mainView(ContainerView of scrollView) should also be a subView of scrollView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM