appDelegate 中的触摸事件 [英] Touch events in appDelegate

查看:24
本文介绍了appDelegate 中的触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题.

我已经在我的应用中实现了推送通知,它工作得很好.

I have implemented push notification in my app and it works just fine.

  • 应用收到一条消息
  • 在 appDelegates 中捕获:didReceiveRemoteNotification
  • 创建一个新的 UIView 来显示收到新消息

我唯一的问题是我希望用户能够点击消息,以便应用程序打开消息视图控制器.但我似乎无法弄清楚如何捕捉这种触摸,然后在 appDelegate 中用它做一些事情.我在应该打开新视图控制器的方法中有一个 NSLog,但它似乎从未被调用过.

Only problem I have is that I want the user to be able to tap on the message so that the app will open the message viewcontroller. But I can't seem to figure out how to capture this touch and then do something with it in the appDelegate. I have an NSLog in the method that should open the new viewcontroller but it seems that it is never called.

任何帮助将不胜感激!

这是代码,它在 didReceiveRemoteNotification 方法中:

Here's the code, it is in the didReceiveRemoteNotification method:

    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoMessages)];
    UIView *messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
    messageView.userInteractionEnabled = YES;
    messageView.backgroundColor = [UIColor darkGrayColor];
    [messageView addGestureRecognizer:recognizer];
    [self.window addSubview:messageView];

谢谢!

推荐答案

我建议您不要为此使用您的应用程序委托类.这不是它的目的,它会导致设计混乱.

I recommend that you not use your app delegate class for this. That's not what it's for and it will lead to disorganized design.

为什么不使用常规视图控制器和 UIView 子类?它们是手势和触摸输入的自然场所.

Why aren't you using a regular view controller and a UIView subclass? They are the natural places for gesture and touch input.

至于为什么您的 NSLog 没有出现,显示该代码也可能会有所帮助.

As for why your NSLog is not appearing, it might be helpful to show that code as well.

您的点击手势识别器似乎配置为允许点击屏幕上的任何位置,而不是像您提到的那样直接点击消息.仅供参考.

Your tap gesture recognizer appears configured to allow any tap anywhere on the screen, as opposed to tapping right on the message, as you mention. Just FYI.

这篇关于appDelegate 中的触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆