I have a scroll view that used to scroll when it didn't have buttons all over it. Now it does, and when dragging the mouse (on simulator) nothing happens (i think because the buttons are being pushed). How can I make this right?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
One thing to try if you're seeing this in a simulator is to run on an actual phone. I couldn't scroll in the simulator but no prob on my phone.
I founded this question looking for the swift solution for this problem, I "translated" it like this:
hope this could help
This is happening because
UIButton
subviews of theUIScrollView
(I assume buttons are added as subviews in your case) are tracking the touches and not the scroll view.UIScrollView
methodtouchesShouldCancelInContentView
is the key here. According to its description: "The default returned value is YES if view is not aUIControl
object; otherwise, it returnsNO
.", i.e. forUIControl
objects (buttons),UIScrollView
does not attempt to cancel touches which prevents scrolling.So, to allow scrolling with buttons:
UIScrollView
propertycanCancelContentTouches
is set toYES
.UIScrollView
and overridetouchesShouldCancelInContentView
to returnYES
when content view object is aUIButton
, like this:In my case, I solved it with this way.
in ViewDidLoad
in .m
Swift 3 Solution