Ali Alebrahim Ali Alebrahim - 1 year ago 166
Swift Question

Buttons are disabled in a ScrollView - iOS Swift

i have a button in a view inside a view inside a ScrollView


if the scrolling ability of the ScrollView is disabled the button clicks normally. However, if the scrolling is enabled the button seems to be disabled.

this is how i sent the content size of the ScrollView

var contentRect = CGRectZero;
for view in self.contentView.subviews {
contentRect = CGRectUnion(contentRect, view.frame)
scrollView.contentSize = contentRect.size
scrollView.contentSize.height = scrollView.contentSize.height+20

and i also sat those properties

scrollView.userInteractionEnabled = true
scrollView.exclusiveTouch = true
scrollView.canCancelContentTouches = true
scrollView.delaysContentTouches = true

and i finally tried to create a subclass of UIScrollView and i ended up with this

class myScrollView: UIScrollView {

override func touchesShouldCancelInContentView(view: UIView) -> Bool {
return false

but still the button is not active whenever there is any scrolling.

Answer Source

Set the color of the ContentView & Scrollview. I think you are setting wrong contentsize. And your PhoneNumberView is outside the contentsize height.


enter image description here

enter image description here

enter image description here

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download