[英]Forward touches to UIPageViewController
我有一個包含UIPageViewController
視圖的容器視圖。 這是在UIViewController
,占據整個屏幕。 在容器視圖的頂部,我有一個UIView
,覆蓋屏幕的一半,其中包含一個按鈕和一些文本。 我想將此UIView
的觸摸轉發到UIPageViewController
。 這樣即使用戶在UIView
滑動, UIPageViewController
仍然可以向左/向右滑動。 我也希望按鈕能夠被按下,因此不能在UIView
上將 isUserInteractionEnabled 設置為 false 。
我該怎么做?
hitTest是確定誰應該使用觸摸/手勢的方法。
所以你的“ UIView
,覆蓋了一半的屏幕”可以從NoTouchHandlerView
類化。 然后這個視圖不會消耗觸摸。 然后它會傳遞給它下面的視圖。
class NoTouchHandlerView: UIView
{
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?
{
if let hitTestView = super.hitTest(point, with: event), hitTestView !== self {
return hitTestView
}else {
return nil
}
}
}
像我這樣的懶人的公認答案的目標 C 版本:)
@implementation NoTouchHandlerView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView* hitTestView = [super hitTest:point withEvent:event];
if (hitTestView != nil && hitTestView != self) {
return hitTestView;
}
return nil;
}
@end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.