[英]Disable scroll of a subview in a UIScrollView
我在滾動視圖的頂部有一個視頻播放器視圖,我添加了垂直滑動來調整音量和亮度功能。
問題是當我在播放器視圖中滑動以調整音量時,滾動視圖也會滾動,我該如何防止呢?
這可能適用於您的用例。
我假設您在視頻視圖上添加了一個pan gesture
,因此在您的操作處理程序中,您可以在手勢的 state 為.began
或.changed
時禁用滾動視圖滾動,並為任何 state 重新啟用它,例如ended
或cancelled
這是我的做法:
@objc
func didPan(_ panGesture: UIGestureRecognizer)
{
scrollView.isScrollEnabled
= panGesture.state != .began && panGesture.state != .changed
/* The above is the same as these lines of code
if panGesture.state == .began || panGesture.state == .ended
{
scrollView.isScrollEnabled = false
return
}
scrollView.isScrollEnabled = true
*/
}
以下是此代碼所發生情況的示例:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.