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

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

问题描述

这是我的问题.

我已经在我的应用程序中实现了推送通知,并且效果很好.

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

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

我唯一的问题是我希望用户能够点击消息,以便该应用程序打开消息视图控制器.但我似乎无法弄清楚如何捕获此触摸,然后在appDelegate中对其进行操作.我的方法中有一个NSLog应该可以打开新的viewcontroller,但似乎从未调用过它.

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天全站免登陆