gpt4 book ai didi

objective-c - touches 在 UIView 与 UIViewControllers 中的触摸事件处理

转载 作者:搜寻专家 更新时间:2023-10-30 19:50:09 26 4
gpt4 key购买 nike

因此,我正在捕获多个触摸并确定每次触摸的数量和位置,并且我看到了 UIView UIViewController 之间的不同行为。

基本上,事件处理程序的编码如下:(在本例中为 touchesEnded,但这并不重要)。在 View 中发生的事情是,我得到了整个触摸集合,但在 Controller 中,我一次只得到一个触摸,也就是说从来没有触摸集合,但是 TouchesEnded 会为发生的每个触摸执行在同一时刻。

我尽可能添加相同的 subview ...有人可以告诉我这是怎么回事吗?为什么 Controller 版本不给我集合?

-(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 是否相同并且具有相同的 subview 。

关于objective-c - touches 在 UIView 与 UIViewControllers 中的触摸事件处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1494990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com