作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
iPhone 应用程序编程指南的事件处理部分中的示例代码“处理复杂的多点触摸序列”提供了一个不完整的示例,假设读者了解足够的填空知识。我知道的足够多,但如果没有一些澄清,我的了解还不足以做到这一点。
在 list 3-6 中,我假设 touchBeginPoints
是 CFDictionaryRef
类型的成员属性。对吗?
在同一示例中,我们使用了 malloc()
,因此我假设我们需要在稍后的某个时刻调用 free()
。我的问题是我要释放什么以及何时释放?我应该free()
touchesEnded:
/touchesCancelled:
中的各个点吗?我该怎么做呢? (我假设我需要阅读枚举 CFDictionaryRef
)或者我会在我的 dealloc:
方法中使用 free(touchBeginPoints);
吗?
最后, list 3-7 中有一个 compareAddress:
方法。我将如何(以及在哪里)实现它?
更新已找到 the answer到最后一个。
最佳答案
释放
键,您可能希望在创建字典时传入自定义释放回调。当字典本身被释放时,会为字典中的每个元素调用键释放回调。 (有关详细信息,请参阅 CFMutableDictionaryCreate
的最后两个参数。)compareAddress:
看起来像:
@interface UITouch (TouchSorting)
- (NSComparisonResult)compareAddress:(id)obj;
@end
@implementation UITouch (TouchSorting)
- (NSComparisonResult)compareAddress:(id)obj {
if ((void *)self < (void *)obj) return NSOrderedAscending;
else if ((void *)self == (void *)obj) return NSOrderedSame;
else return NSOrderedDescending;
}
@end
关于iphone - 如何处理复杂的多点触控序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1903042/
我是一名优秀的程序员,十分优秀!