Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何知道正在接收当前手势的视图_Iphone_Ios_Objective C_Uiview_Uikit - Fatal编程技术网

Iphone 如何知道正在接收当前手势的视图

Iphone 如何知道正在接收当前手势的视图,iphone,ios,objective-c,uiview,uikit,Iphone,Ios,Objective C,Uiview,Uikit,我有一个ui按钮,当我点击其中一个非常小的子区域时,它只对我的点击手势做出反应。当我在按钮内的其他位置点击时,可能另一个视图正在吞咽我的手势 问题是。。有没有办法知道哪个UIView正在接收抽头?我知道我可以用蛮力将所有手势处理程序都附加到我的所有视图上。。但似乎工作太多了。有什么想法吗 更新: 下面艾哈迈德的回答非常有效。。我还添加了UIView以快速找到令人不快的视图 即如果我在NSLog行上放置断点: - (void)sendEvent:(UIEvent *)event { [su

我有一个
ui按钮
,当我点击其中一个非常小的子区域时,它只对我的点击手势做出反应。当我在按钮内的其他位置点击时,可能另一个视图正在吞咽我的手势

问题是。。有没有办法知道哪个
UIView
正在接收抽头?我知道我可以用蛮力将所有手势处理程序都附加到我的所有视图上。。但似乎工作太多了。有什么想法吗

更新: 下面艾哈迈德的回答非常有效。。我还添加了UIView以快速找到令人不快的视图

即如果我在NSLog行上放置断点:

- (void)sendEvent:(UIEvent *)event
{
    [super sendEvent:event];
    UIView *touchReceipientView =((UITouch *)[event.allTouches anyObject]).view;
    NSLog(@"View = %@ ",touchReceipientView);
}
我得到以下输出(作为示例):

(lldb)po[touchReceipientView recursiveDescription]
| 
|    | 
|    | 

这让我立刻发现了令人不快的UIView

您可以将UIApplication子类化,并查看谁正在接收事件

总的来说,m

@interface MyApplication : UIApplication

@end


@implementation MyApplication

- (void)sendEvent:(UIEvent *)event
{
    [super sendEvent:event];
    NSLog(@"View = %@",  ((UITouch *)[event.allTouches anyObject]).view);
}

@end





int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([MyApplication class]), NSStringFromClass([MyAppDelegate class]));
    }
}

从应用程序的关键窗口开始,循环浏览视图,并向其发送
isFirstResponder
。手势识别器。view@Desdenova如果我已经有了手势识别器对象,我想这个问题很简单,不是吗?@H2CO3。。有意思。。我不知道能从中得到什么。。但我还是要试试看会发生什么。。谢谢我的错,我以为你在使用识别器。我猜你的意思是
@implementation-MyApplication
对吧?
@interface MyApplication : UIApplication

@end


@implementation MyApplication

- (void)sendEvent:(UIEvent *)event
{
    [super sendEvent:event];
    NSLog(@"View = %@",  ((UITouch *)[event.allTouches anyObject]).view);
}

@end





int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([MyApplication class]), NSStringFromClass([MyAppDelegate class]));
    }
}