向用户展示 iPhone 上正在加载某些内容的最佳方式是什么?

发布于 2024-08-07 04:20:17 字数 779 浏览 10 评论 0原文

最近,我一直在寻求创建某种方式来向用户显示正在加载某些内容。我确信任何拥有 iPhone 的人都见过这个应用程序,但是最好的方法是什么?

我开始使用 UIProgressHUD,但是有人向我指出你不应该'并没有真正使用私有(未记录的)API。

然后我转向 this 这是一个自定义版本称为 MBProgressHUD,但是根据我的经验,当尝试不从按钮调用它时,不会显示加载部分,并且我发现它非常错误(只需单击即可使示例代码崩溃并不难) 。

然后我继续在 James Brannan 的书中找到了这个,但我不太确定为什么他声称这是“正确的方法”,因为我过去见过许多带有类似 UIProgressHUD 的应用程序。

有人有什么想法吗?

编辑:这非常好......

谢谢

Recently I've been looking to create some way of showing a user that something is being loaded. I'm sure anyone with an iPhone has seen this is apps before but what is the best way of doing it?

I started using UIProgressHUD, however it was pointed out to me that you shouldn't really use private (undocumented) API's.

I then I moved onto this which is a custom version called MBProgressHUD, however in my experience with this is wouldn't show the loading part when trying to call it not from a button and I found it very buggy (It wasn't very hard to crash the example code given by just clicking away).

I then went on to find this by James Brannan from his book, however I'm not quite sure why he claims this is the "proper way" of doing it when I've seen many apps in the past with what looks like the UIProgressHUD.

Does anyone have any ideas?

EDIT: This is pretty good...

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花辞树 2024-08-14 04:20:17

没有一种“最好”的方法。另一种方法是简单地将 UIView 放在主视图的子视图之上,标记其 userInteraction 属性,并在需要时将其灰显。您甚至可以添加一个 UIActivityIndi​​cator 作为此“前景”UIView 的子视图,在需要时启动其动画。加载完成后,隐藏/停止活动指示器并清除前景视图的颜色。

There is no one "best" way. Another way to do this is to simply put a UIView atop your main view's subviews, mark its userInteraction property and grey it out when needed. You could even add a UIActivityIndicator as a subview of this "foreground" UIView, starting its animation when needed. When your loading has finished, hide/stop the activity indicator and clear the foreground view's color.

公布 2024-08-14 04:20:17

如果您正在谈论通过网络加载,那么首先要做的一件好事是启用状态栏网络活动指示器:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

请注意,完成后必须将其设置为“否”!这应该仅用于指示网络活动。

虽然这有点微妙,但拥有某种进度指示器是个好主意如果您可以准确地知道某件事将花费多长时间 - 下载您知道大小并计算传入字节数的地方,或者上传您还可以在其中监视传出的字节并了解总大小。

如果您的调用长度非常小或者大小并不真正已知(Web 服务调用就是一个很好的例子),那么使用 UIActivityIndi​​cator 进行某种覆盖可以非常轻松(您还可以制作一个自定义变体,将一组图像添加到用于动画的 UIImage 视图)。关键是,如果可能的话,它不应该阻止用户做其他事情。

此外,如果您有多种情况发生,您可能需要添加描述您所处状态的消息(例如“调整图像”、“上传图像”等)。

If you are talking about loading over a network, one good thing to start with is to enable the status bar network activity indicator:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

Note that you have to set it to NO when you are done! That should only be used to indicate network activity.

That's a bit subtle though, it's a great idea to have some kind of progress indicator IF you can tell exactly how long something is going to take - downloads where you know the size and count incoming bytes, or uploads where you also monitor bytes outgoing and know the total size.

If your call length is very small or the size is not really known (web service call is a great example) then some kind of overlay with a UIActivityIndicator can be very relaxing (you can also make a custom variant with a set of images added to a UIImage view to animate). The key is, that if possible it should not block the user from doing other things if possible.

Also if you have multiple things going on, you might want to add messages describing what state you are in (like, "adjusting image", "uploading image", etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文