好吧,我想出答案我自己的問題。不知道這是否是最有效/最乾淨的方式,但它是獲得理想效果的唯一方法。這裏是我的解決辦法:在我OverlayView的,我overridded
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
if miniView.frame.contains(point) || miniView.isOpen {
return true
}
//pass the tap onto other views
return false
}
這基本上讓我說,如果認爲應該有用戶交互,這是我在一定的標準基礎(水龍頭是我MiniView中內部或MiniView中已擴大) 。但是,當我返回錯誤時,它會讓觸摸通過。如果您沒有覆蓋此方法,並且overlayView具有userInteractionEnabled,那麼疊加視圖會逐字地吃掉所有的觸摸。使用這種方法,我仍然可以在overlayView上保留userInteractionEnabled,但決定觸摸何時應該通過其他位置。
然後,在我的parentView,我添加了一個平移手勢。我做了parentView一個UIGestureRecognizerDelegate,並實現了這一功能:
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
//if the final page is the first page (i.e. the user only has one pic), then we don't want swiping that could interfere with the card swipe.
if let pan = gestureRecognizer as? UIPanGestureRecognizer {
let velocity = pan.velocity(in: self)
let isVertical = abs(velocity.x) < abs(velocity.y)
let isUpwards = getPanDirection(velocity: velocity) == .up
return (theBumbleScrollView.isAtFinalPage && isVertical && isUpwards) || theBumbleDetailView.isOpen
}
return true
}
這讓我看到了當平移手勢即將開始,並根據我返回(true或false),這將改變狀態。失敗的平底鍋手勢。基本上,取消它的手勢。這是一個有用的Stack OverFlow post:Limit UIView movement to only vertical or horizontal axis
現在,我的平移手勢失敗了,根據我指定的標準,但我需要告訴我的scrollView,它的平移手勢可以平移,如果我的自定義平移手勢失敗。這就是這個方便的線路進來要求(toFail:...):
let pan = UIPanGestureRecognizer(target: self, action: #selector(self.isPanning(pan:)))
pan.delegate = self
self.addGestureRecognizer(pan)
theScrollView.panGestureRecognizer.require(toFail: pan)
當我設置的移動手勢到父視圖,我主要講述滾動視圖的平移手勢(其中蘋果內置的自動)如果自定義平移手勢失敗,它應該在下一行。
。那是讓我有時滾動滾動視圖我但有時能在我OverlayView的滾動解決方案。希望我能在解決這個問題的那一天拯救某個人。如果有人希望看到示例代碼,我還創建了我的示例項目(視圖名稱不同)的github repo。 https://github.com/danielchangsoojones/Bumble-App-Clone/tree/master