UIScrollView in UIScrollView

I have a hierarchy where UIScrollviews exist inside each other.

How can I redirect swipe events for a specific area to inner scrolling?

+4
source share
2 answers

If you set UIScrollViews to only scroll on one axis or another (i.e. set the contentSize property for them accordingly. To be able to scroll only vertically, set its contentSize.width value to the same as its bounds.size.width) . then they should just work, considering that two types do not scroll on the same axis. Usually, you will have β€œchild” views, scroll vertically, and the parent view scrolls horizontally.

+2
source

If at all possible, you should redesign to avoid this. Safari handles this situation, i.e. iframes and textareas, with a built-in two-finger scroll view. It is not very easy to detect, but it is better than an alternative that will be even more unpleasant. If the built-in view was barely filmed, an attempt to scroll through the appearance might instead scroll inside, but not display a lot of anything; he just looks immune.

However, if you still want to do this, try canCancelContentTouches scroll canCancelContentTouches to NO . This should prevent scrolling of the appearance when the touch starts in the internal view. Getting a two-finger scroll in Safari style is likely to involve subclassing UIScrollView and implementing the -touchesShouldBegin:withEvent:inContentView: .

+1
source

Source: https://habr.com/ru/post/1303175/


All Articles