如何在iPhone上显示进度指示器叠加/ HUD? [英] How to display a progress indicator overlay/HUD on iPhone?

查看:130
本文介绍了如何在iPhone上显示进度指示器叠加/ HUD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在半透明框中显示一个进度指示器,浮动在表视图上。换句话说,当表格内容被下载时,我想要一个更新标签出现在它上面。



我在商店里的几个应用程序中看到这个,特别是Facebook(当你摇晃重新加载)和Darkslide。



我的第一个冲动是创建一个半透明的UIView,在其中放置一个UILabel和一个UIProgressIndicatorView,它到视图层次结构...但在哪里? 一个UIView可能不会重叠它的兄弟姐妹,所以我不能使它的窗口的子视图。 我也不能使它成为表的子视图,因为它将随着表内容向上和向下滚动。



我考虑创建新的UIWindow,但文档基本上说不要



我知道CALayers可以互相重叠,所以这将是一个选项,但我不能把进度指示器放在CALayer内,可以吗?我应该滚动自己的进度指示器,动画CALayer而不是UIView?



我不感兴趣听到私人API



这个问题是基于一个错误的假设。 NSViews(在Mac OS X上)可能不重叠,但iPhone上的UIView可能会。

解决方案

只需在tableView中添加透明叠加层作为子视图。



从UIView的文档:


UIView对象在UIWindow对象中排列在子视图的嵌套层次结构中。视图层次结构中的父对象称为超级视图,子级称为子视图。视图对象声明其包围的超级视图的矩形区域,负责该区域内的所有绘制,并且也有资格接收其中发生的事件。 Sibling视图可以重叠,没有任何问题,允许复杂的视图位置。



I want to display a progress indicator in a semi-transparent box that floats over a table view. In other words, when the table contents are being downloaded, I want an "Updating" label to appear over it.

I have seen this in several apps in the store, notably Facebook (when you shake to reload) and Darkslide.

My first impulse is to create a semi-transparent UIView, place a UILabel and a UIProgressIndicatorView inside it, and add it to the view hierarchy... but where? A UIView may not overlap its siblings, so I can't make it a subview of the window. I also can't make it a subview of the table, because then it will scroll up and down with the table content.

I thought about creating a new UIWindow, but the documentation basically says don't.

I know CALayers can overlap each other, so that would be an option, but I can't put a progress indicator inside a CALayer, can I? Should I roll my own progress indicator that animates a CALayer instead of a UIView?

I'm not interested in hearing about private APIs.

Edit: The question was based on a faulty assumption. NSViews (on Mac OS X) may not overlap, but UIViews on the iPhone may.

解决方案

You can definitely overlap views. Just add the transparent overlay as a subview in the tableView.

From UIView's documentation:

UIView objects are arranged within an UIWindow object, in a nested hierarchy of subviews. Parent objects in the view hierarchy are called superviews, and children are called subviews. A view object claims a rectangular region of its enclosing superview, is responsible for all drawing within that region, and is eligible to receive events occurring in it as well. Sibling views are able to overlap without any issues, allowing complex view placement.

这篇关于如何在iPhone上显示进度指示器叠加/ HUD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆