![](/img/trans.png)
[英]Can an iOS View handle gestures and direct touch events at the same time?
[英]Handle touch gestures in two views
我有兩個UIScrollViews
在層次結構中一個接一個。 我將其命名為: scrollView1
是從前面view
,而scrollView2
是從后面view
。
所述scrollView1
具有transparent
view
中CGRect(0,0,320,568)
和一些content
中CGRect(0,568,320,300)
如果用戶垂直滾動屏幕,則需要查看從y = 568
的視圖。
所述scrollView2
包含一些UIImages
水平地顯示,每個image
開始於origin.x = screenWidth * imageIndex
,其中imageIndex
從開始0
。 因此scrollView2
必須在images
水平scroll
,並且content
還包含一些UIButtons
。
如何做才能垂直scroll
scrollView1
但同時又可以水平scroll
scrollView2
並在其按鈕上觸發UIButtonEventTouchUpInside
。 方法- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
對我沒有幫助,因為我必須選擇是否使用當前view
句柄。
謝謝你的幫助!
我認為您必須檢查添加了哪個手勢。
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture shouldReceiveTouch:(UITouch *)touch
{
// enter code here
}
對於:
我該怎么做才能垂直滾動scrollView1,但同時又能水平滾動scrollView2
您需要將UISwipeGestureRecognizer實現為:
- (void)didSwipe:(UISwipeGestureRecognizer*)swipe{
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Swipe Left"); // Implement Horizontal Scroll
} else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"Swipe Right"); // Implement Horizontal Scroll
} else if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"Swipe Up"); // Implement Vertical Scroll
} else if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"Swipe Down"); // Implement Vertical Scroll
}
}
對於:
UIButtonEventTouchUpInside
我不確定您要實現的目標,但是如果您的視圖重疊(一個視圖在另一個視圖之后),則需要通過更改其YourTargetView.zPosition
將目標視圖置於最前面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.