2
A
回答
4
可以實現對UIPanGestureRecognizer委託方法。檢查手勢的位置是否在您感興趣的邊界內。對於應該*方法,您可以返回false來取消手勢。手勢一旦開始,您可以通過將State屬性設置爲Cancelled來取消它。
public class GestureView: UIView
{
RectangleF _bounds;
public GestureView (RectangleF rect) : base (rect)
{
this.BackgroundColor = UIColor.Brown;
UIPanGestureRecognizer pan = new UIPanGestureRecognizer (this, new Selector ("panViewWithGestureRecognizer:"));
this.AddGestureRecognizer (pan);
pan.WeakDelegate = this;
_bounds = new RectangleF (0,0,200, 100);
}
[Export("panViewWithGestureRecognizer:")]
void PanGestureMoveAround (UIPanGestureRecognizer p)
{
if (_bounds.Contains (p.LocationInView (this)))
{
Console.WriteLine ("PanGestureMoveAround true");
return;
}
Console.WriteLine ("PanGestureMoveAround false");
p.State = UIGestureRecognizerState.Cancelled;
return;
}
[Export ("gestureRecognizerShouldBegin:")]
bool ShouldBegin (UIGestureRecognizer recognizer)
{
if (_bounds.Contains (recognizer.LocationInView (recognizer.View)))
{
Console.WriteLine ("ShouldBegin true");
return true;
}
Console.WriteLine ("ShouldBegin false");
return false;
}
[Export ("gestureRecognizer:shouldReceiveTouch:")]
public bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
{
if (_bounds.Contains (touch.LocationInView (recognizer.View)))
{
Console.WriteLine ("ShouldReceiveTouch true");
return true;
}
Console.WriteLine ("ShouldReceiveTouch false");
return false;
}
}
相關問題
- 1. 有限的滑動區域Android
- 2. UIScrollView有限的滾動區域
- 3. Swift中的有限區域Pinchview
- 4. 限制UISwipeGestureRecognizer區域
- 5. 僅限區域內的MKAnnotation
- 6. 在有限區域中繪製圖像
- 7. 可滾動區域有寬度限制?
- 8. UIScrollview限制刷卡區域
- 9. DirectX限制繪圖區域
- 10. Libgdx CameraController限制區域
- 11. 限制uiscrollview滾動區域
- 12. 限制滾動區域
- 13. 重複panGestureRecognizer?
- 14. 有沒有可能爲tvOS使用PanGestureRecognizer?
- 15. 如何在Symfony2中同時創建受限區域和非受限區域
- 16. IOS7將MapView限制在某個區域或區域
- 17. PanGestureRecognizer取消UIButton按
- 18. 限制UIScrollView中的滾動區域
- 19. 使用受限制的執行區域
- 20. iBeacon - 監控區域的最大限制
- 21. Android的無線覆蓋區域限制
- 22. 限制文本區域的字符
- 23. 區域和迭代,需要的權限
- 24. 限制按鈕的點擊區域
- 25. AppFabric Cache中的區域名稱限制
- 26. 限制特定區域內的服務
- 27. 限制qgraphicsitem的可移動區域
- 28. Zxing.Net中的掃描區域限制
- 29. Symfony2的有限列表區域的表單元素
- 30. 問題與PanGestureRecognizer的價值
謝謝你,「_bounds.Contains」非常有幫助;) – Alex