2015-06-26 40 views
0

我有一個UIViewController創建自定義UIView對象並將它們插入到UIScrollView。該UIViewController附加一個UIPanGestureRecognizer每個UIView。是否有什麼我可以做,以使UIScrollView的滾動甚至當它正在通過定製感動UIView對象,同時仍允許其UIPanGestureRecognizers(被配置爲改變X座標只)工作?Swift:識別滾動通過UIView

這裏是我的意思的屏幕截圖。藍色矩形是自定義的UIView對象,白色背景是UIScrollViewenter image description here

任何幫助將不勝感激!

+0

在做了一些更多的研究之後,它好像使用'UIGestureRecognize rDelegate'(https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/index.html)就是這樣做的方法。問題是,由於我是Swift新手,我不知道如何使用它。如果有人知道如何使用'gestureRecognizer(_:shouldRecognizeSimultaneouslyWithGestureRecognizer:)',我將非常感謝指導。 – DefinitelyNotAPlesiosaur

回答

0

我想通了!

這是所有關於使用UIGestureRecognizerDelegate

在頂部,你做class ViewController: UIViewController, UIGestureRecognizerDelegate

然後,在類主體中,添加這個方法:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true }

最後,在UIView之上,添加panRecognizer.delegate = selfpanRecognizer是引用UIView的變量UIGestureRecognizer

+0

你可以添加一些更多的代碼細節。我沒有得到UIView部分。我對swift也很陌生 – Somu

+0

這是解決這個特定問題所需的所有代碼。哪部分是你需要幫助的? – DefinitelyNotAPlesiosaur