如何在给定的时间内显示 NSArray
我是新开发人员,正处于在 iPhone 上编写供个人使用的简单词典应用程序的初级阶段,我想知道使用什么方法来控制我的单词在屏幕上显示的时间。
我已经尝试过 NSTimer 和 performSelector:withObject:afterDelay: ,但我想知道这些是否是解决问题的最简单、最有效的方法。
我不确定是否应该使用像 NSThread sleepForTimeInterval:
这样的睡眠方法,因为我希望可以选择在单词列表显示在屏幕上时在应用程序中进行其他操作。
有什么指点吗?
一百万谢谢。
I'm new developer in the beginning stages of writing a simple dictionary app for personal use on the iPhone, and I'm wondering what method to use to control how long my words are displayed on screen.
I've experimented with NSTimer
and performSelector:withObject:afterDelay:
but Im wondering if these are the simplest, most efficient ways to approach the problem.
I'm not sure if I should use a sleep method like NSThread sleepForTimeInterval:
because I'd like to have the option to have other things going on in the app while the word list is on screen.
Any pointers?
A million thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSTimer
或performSelector:withObject:afterDelay:
都是不错的选择。在我看来,performSelector:withObject:afterDelay: 似乎使用起来更直接。您不想使用睡眠,尤其是在主线程上。这将使您的应用程序无响应。
您可能还想查看块动画。例如,您可以淡出该词,然后淡出。请参阅:
[UIView animateWithDuration:delay:options:animations:completion:]
。一开始会有点令人生畏,特别是如果您不熟悉代码块的话。但这种方法给了你很多控制权。NSTimer
orperformSelector:withObject:afterDelay:
are both good options. TheperformSelector:withObject:afterDelay:
seems more straight forward to use, in my opinion.You don't want to use sleep, especially on the main thread. This will make your app unresponsive.
You might also want to look at block animations. You could, for example, fade the word on then off. See:
[UIView animateWithDuration:delay:options:animations:completion:]
. It is a little more intimidating at first, especially if you are not familiar with code blocks. But this method gives you lots of control.您可以使用 Grand Central Dispatch 的dispatch_after 功能:
You can use Grand Central Dispatch's dispatch_after functionality: