用 KVO 观察 UIImage?
我的模型对象有一个经常异步更新的 UIImage *iconImg
。我希望允许其他类的实例优雅地观察 myModel.iconImg
的任何更改。现在,我的异步图像获取类采用 UIImage**
(是的,丑陋,但它正在工作)。然而问题是,通过指针搞乱 UIImage 会绕过我可能喜欢使用属性的任何 KVO,所以我必须使用我不太喜欢的 NSNotification。以下是主要要求:
- 即使没有视图准备好显示它(即没有 UIImageView 准备好),我也希望能够加载 iconImg 理想
- 情况下,只有选择观察特定<的实例strong>
myModel.iconImg
实例将意识到更改(与我当前必须过滤的通知不同) - 我有几个带有
iconImg
所有属性都需要以这种方式工作,而不仅仅是一个 如果需要,我可以更改我的图像获取器类(这是当前的签名):
+ (BOOL)asyncImageFetch:(UIImage**)anImagePtr withURL:(NSURL*)aUrl;
不确定这有多清楚,所以请告诉我是否可以详细说明任何内容。
谢谢,
史蒂夫
My model object has a UIImage *iconImg
that is often updated asynchronously. I want to allow instances of other classes to observe any changes to myModel.iconImg
elegantly. Right now, my asynchronous image fetch class takes a UIImage**
(yes, ugly, but it's working). The problem, however, is that messing with the UIImage via pointers bypasses any KVO I might have enjoyed using properties, so I have to use NSNotification which I'm not a big fan of. Here are the main requirements:
- I want to be able to load iconImg even when no views are ready to display it (ie no UIImageView is ready)
- Ideally, only the instances that have elected to observe the specific
myModel.iconImg
instance will be made aware of changes (unlike with Notifications where I currently have to filter) - I have several model classes with
iconImg
properties that all need to work this way, not just one I can change my image fetcher class if necessary (here's current signature):
+ (BOOL)asyncImageFetch:(UIImage**)anImagePtr withURL:(NSURL*)aUrl;
Not sure how clear that is, so let me know if I can elaborate on anything.
Thanks,
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何有类似需求的人,请查看 SDWebImage(看起来 Olivier Poitrey 是原作者)。 Github 存储库位于:https://github.com/rs/SDWebImage。
我一直在使用它,非常好。
For anyone looking with similar requirements, take a look at SDWebImage (looks like Olivier Poitrey is the original author). Github repository here: https://github.com/rs/SDWebImage.
I've been using it and it's very nice.