[英]touches in touch event handling in UIView vs UIViewControllers
因此,我正在捕獲多次觸摸並確定每次觸摸發生的次數和位置,並且我看到 UIView UIViewController 之間的行為不同。
基本上,事件處理程序的編碼如下:(在這種情況下,touchesEnded,但它真的無關緊要)。 在視圖中發生的事情是,我獲得了整個觸摸集合,但在控制器中,我一次只得到一個觸摸,即從來沒有觸摸集合,但是 TouchesEnded 會針對發生的每次觸摸執行在同一時刻。
我添加了盡可能相同的子視圖......有人可以告訴我這是怎么回事嗎? 為什么控制器版本不給我收藏?
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
int total = 0;
for (UITouch *touch in touches)
{
for(UIView *myView in [contentView subviews])
{
if (CGRectContainsPoint([myView frame], [touch locationInView:self.view]))
total++; // this is always 1 for the UIViewController
// but I get the full number within the UIView version
}
}
}
我懷疑你正在接觸,但觀點不同。 檢查 contentView 是否相同並且具有相同的子視圖。
我不確定我是對的,但這件事總是對我有用。
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
If(touch.view==your view)
{
NSLog("do your task here");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.