繁体   English   中英

触摸通知已结束

[英]notification for touches ended

我是关于iPhone通知的小新手。

我想做的是:我有一个使用基于UIImageView的类的对象。 此类具有自己的touchbegan,touchesended等实现。

主程序是否可以知道用户何时将手指从对象上抬起? 换句话说,是否可以创建一个从类到主应用程序的视图控制器的通知(使用该类),从而触发一个方法? 该方法应该在主应用程序上,而不在类上。

这可能吗? 能给我举个例子吗?

谢谢你的帮助。

-touchesEnded: ,添加类似以下语句的内容(将handleTouchesEndedNotification更改为要用于通知的唯一名称):

[[NSNotificationCenter defaultCenter] postNotificationName:@"handleTouchesEndedNotification" object:nil userInfo:nil];

在您的主应用程序委托或其他类中,在初始化该类的位置添加以下语句,该语句侦听具有您在上面使用的唯一名称的通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMyNotification:) name:@"handleTouchesEndedNotification" object:nil];

在类中进一步添加方法和逻辑:

- (void) handleMyNotification:(NSNotification *)notification {
    // do stuff...
}

如果要与通知一起传递数据,请创建一个NSDictionary对象,并将通知的userInfo变量设置为此字典对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM