Forward touches to a UIScrollView

后端 未结 4 1301
一个人的身影
一个人的身影 2021-01-04 08:32

I have two view controllers. View controller A has a UIScrollView and presents view controller B. The presentation is interactive and controlled by the sc

4条回答
  •  既然无缘
    2021-01-04 09:11

    After reading an interesting answer describing UIScrollView's event flow, I came to the conclusion that trying to "remote control" a scroll view from a gesture recognizer is probably very hard to achieve because touches are mutated while being routed to views and gesture recognizers. Since UITouch doesn't conform to NSCopying we also can't clone touch events in order to send them later in unmodified state.

    While not really solving the problem I asked for, I found a workaround to accomplish what I need. I just added a scroll view to view controller B and synced it with VC A's scroll view (which is added to the view hierarchy when vertically scrolling):

    // delegate of VC B's scrollView
    - (void)scrollViewDidScroll:(UIScrollView*)scrollView
        scrollViewA.contentOffset = scrollView.contentOffset;
    }
    

    Thanks to Friedrich Markgraf who came up with the idea.

提交回复
热议问题