I've made a program which contains pictures that can be dragged to move on the screen. also I used UIScrollView since the space is larger than the window. I subclassed UIView as a pictures view to display the picture and handle touches in this class. picture views are added as subviews to the scrollView. but now I have a problem: when I drag the picture, the scrollView moves together with the picture. I'm wondering if there is a way to consume the touches in the picture class to prevent them from passing to superview.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
You should to put your code in "touchesMoved:withEvent:" method of your UIView. If your View will handle this event by yourself, then it should not bubble to superview
I know this is an old question, but I had a similar issue and the approved answer (setting
canCancelContentTouches
tofalse
in the scroll view andisExclusiveTouch
totrue
in the subview) did not work for me.After some experimentation, I found that simply overriding
gestureRecognizerShouldBegin(_:)
in my subview to returnfalse
solved the problem:You need subclass
UIScrollView
and overridetouchesShouldCancel
:As a bonus you may want to
scrollView.delaysContentTouches = false
for instant response on your custom controls.why you use
UIScrollView
? You have you own scroll picture view so there is no need to use theUIScrollView
to handle the scroll touch input.other way around, why you use you own scroll picture view?
UIScrollView
will handle scrolling case so you can just put anUIImageView
underUIScrollView
which will work the same unless your own view have some other behaviour but you can subclassingUIImageView
orUIView
and no need to scroll the picture by you own because you knowUIScrollView
will do it for you.Icewind's comment above solved the problem:
You can try to set canCancelContentTouches to NO in your UIScrollView. And set exclusiveTouch to YES in your UIView with image – icewind Mar 7 at 14:22