[英]Prevent touch transfer to superview from UIImageView
我有一個自定義的垂直范圍滑塊,並使用 touchBegan、touchMoved 和 touchEnded 處理頭部的運動。 當我嘗試滑動頭部時,它會滑動一點,然后取消觸摸並在 iOS 13 上開始交互式關閉轉換。我想防止在滑動時將觸摸轉移到超級視圖。 我們如何才能做到這一點。
提前致謝。
嘗試將另一個手勢識別器用於帶有另一個選擇器的視圖
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappedOnBubble)];
[self.bubbleView addGestureRecognizer:tap];
UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappedOnMainView)];
[self.view addGestureRecognizer:tap2];
-(void)tappedOnMainView
{
NSLog(@"touched on main View");
[self.vwToShow setHidden:NO];
}
-(void)tappedOnView
{
NSLog(@"tapped on slider");
[self.vwToShow setHidden:YES];
}
UIView 繼承自 UIResponder,基本的觸摸事件由觸發觸摸開始事件的視圖檢測。 您在主視圖中添加的子視圖也響應觸摸開始方法。這是非常基本的。 您還添加了一個帶有點擊手勢識別器的選擇器方法。
如果您仍然想使用 touchBegan ,我認為您應該這樣做:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
if(theTouchLocation is inside your bubble)
{
do something with the touch
}
else
{
//send the touch to the next view in the hierarchy ( your large view )
[super touchesBegan:touches withEvent:event];
[[self nextResponder] touchesBegan:touches withEvent:event];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.