gpt4 book ai didi

iphone - 将 UIView/UIWindow 中的特定触摸事件传递给下一个响应者(sendEvent :/hitTest: doesn't work )

转载 作者:行者123 更新时间:2023-12-01 16:57:43 30 4
gpt4 key购买 nike

我试图在不破坏其功能的情况下捕获 UIKeyboard 中的所有触摸事件。我试过了:

  • HitTest :
  • UIGestureRecognizer
  • 在顶部添加一个 UIWindow 并将事件传递给下一个响应者

  • 然而,这些都没有奏效。

    而且似乎我们不允许对 UIKeyboard 进行子类化。

    你能想到任何可行的方法吗?

    谢谢,

    顶峰

    更新:

    让我们简化问题:如何添加将特定触摸事件传递给下一个响应者的 UIView 或 UIWindow(就像将 userInteractionEnabled 设置为 NO 一样)?

    这是我的代码(当然不能工作......):
       - (void)sendEvent:(UIEvent *)event {
    NSLog(@"%@",event);
    //if ([self eventIsNoteworthy:event]) [self extraEventHandling:event];
    [super sendEvent:event]; // Apple says you must always call this!
    }

    -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    CGPoint hitPoint = [underneathButton convertPoint:point fromView:self];
    if ([underneathButton pointInside:hitPoint withEvent:event]) return underneathButton;
    NSLog(@"Called");
    return [super hitTest:point withEvent:event];
    //return mainWindow;
    }

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"Start");

    [self.nextResponder touchesBegan:touches withEvent:event];

    }

    最佳答案

    我不确定这是否可能。我想到了几件事。一种是重新创建 UIKeyboard自己,然后以这种方式捕捉触摸。 Apple Docs说明这是可能的。

    另一种方法是重新查看您是如何在键盘上方添加 UIWindow 的。据我了解,键盘 View 在您的应用程序上以某种方式分层,因此您可能没有将 UIWindow 置于键盘上方 (ref) .该链接提供了一个解决方案,用于获取对键盘实际 UIView 的引用,从那里您希望将 UIWindow 放置到键盘 View 的父级上。

    为了提供帮助,这里有一个脚本,您可以使用它来转储所有 View 以查看它们是如何分层的:

    static void dumpViews(UIView* view, NSString *text, NSString *indent) 
    {
    Class cl = [view class];
    NSString *classDescription = [cl description];
    while ([cl superclass])
    {
    cl = [cl superclass];
    classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]];
    }

    if ([text compare:@""] == NSOrderedSame)
    NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame));
    else
    NSLog(@"%@ %@ %@", text, classDescription, NSStringFromCGRect(view.frame));

    for (NSUInteger i = 0; i < [view.subviews count]; i++)
    {
    UIView *subView = [view.subviews objectAtIndex:i];
    NSString *newIndent = [[NSString alloc] initWithFormat:@" %@", indent];
    NSString *msg = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i];
    dumpViews(subView, msg, newIndent);
    [msg release];
    [newIndent release];
    }
    }

    像这样称呼它: dumpViews([[UIApplication sharedApplication] keyWindow], @"", @"");
    希望能有所帮助! :D

    关于iphone - 将 UIView/UIWindow 中的特定触摸事件传递给下一个响应者(sendEvent :/hitTest: doesn't work ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10091876/

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