I have a button in a view inside a view inside a ScrollView:
UIScrollView
-ContentView
--PhoneNumberView
---UIButton
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 set 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.
How can I fix that?
Set the color of the ContentView
& Scrollview
. I think you are setting wrong contentsize
. And your PhoneNumberView
is outside the contentsize
height.
EDIT
By setting
scrollView.exclusiveTouch = true
you tell scrollView to handle touches exclusively, so touches won't reach its subviews, so set this property to false
This line of code
scrollView.delaysContentTouches = true
basically delays touches on scrollview subviews, if you want button to respond immediately then set this property to false
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With