簡體   English   中英

在兩個視圖中處理觸摸手勢

[英]Handle touch gestures in two views

我有兩個UIScrollViews在層次結構中一個接一個。 我將其命名為: scrollView1是從前面view ,而scrollView2是從后面view

所述scrollView1具有transparent viewCGRect(0,0,320,568)和一些contentCGRect(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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM