[Activity Indicators]简介

Activity Indicators

An activity indicator is a spinning wheel that indicates a task is in the midst of being processed. If an action takes a noticeable and indeterminate amount of time to process—such as a CPU-intensive task or connecting to a network—you should display an activity indicator to give assurance to the user that your app is not stalled or frozen.

活跃指示器 是一个旋转的轮子表示一个任务正在处理中。如果一个动作花费了值得注意的、不确定的大量的时间去处理,比如一个CPU消耗大的任务或者网络连接。这种情况下你应该显示一个活跃指示器来让用户确信你的app没有停止运转或者卡住。

image: ../Art/uiactivityindicator_intro.png

Purpose. Activity indicators allow users to:

  • Receive feedback that the system is processing information

Implementation. Activity indicators are implemented in the UIActivityIndicatorView class and discussed in the UIActivityIndicatorView Class Reference.

Configuration. Configure activity indicators in Interface Builder, in the Activity Indicator section of the Attributes Inspector. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. You can set other configurations programmatically, too, if you prefer.

在Interface Builder的Activity Indicator 的Attributes Inspector里面配置activity indicator。有一些配置时不可以通过属性检查器来设置,所以一定要通过编程来实现。当然,如果你更喜欢的话,其他属性也可以通过编程的方法来实现。

image: ../Art/uiactivityindicatorview_attributes_inspector_plain_2x.png

Content of Activity Indicators

An activity indicator is indeterminate, and has no starting or ending values associated with it.

活跃指示器是不确定的,没有与之相关的起始值活着结束值。

Behavior of Activity Indicators

The Animating (isAnimating) box is unchecked by default; checking it causes the activity indicator to start animating. This is the equivalent of calling the startAnimating method.

动画框是默认勾选的;勾选这个会使活跃指示器开始动画。这与调用startAnimating方法是等价的。

Select the Hides When Stopped (hidesWhenStopped) field in the Attributes Inspector for your activity indicator to disappear when the animation ends. When you call the startAnimating and stopAnimating methods, the activity indicator automatically shows and hides onscreen. This way, you won’t have to worry about displaying a stationary activity indicator.

在属性检查器中勾选hides when stopped框来使activity indicator在动画结束时消失。当你调用startAnimating和stop Animating方法,activity indicator 会自动地在屏幕上显示和隐藏。这样子,你将不必担心展示了固定的activity indicator。

image: ../Art/uiactivityindicatorview_attributes_inspector_plain_2x.png

Appearance of Activity Indicators

You can customize the appearance of an activity indicator by setting the properties depicted below.

你可以通过如下描绘的属性来自定义activity indicator的外观。

image: ../Art/uiactivityindicator_callouts.png

To customize the appearance of all activity indicators in your app, use the appearance proxy (for example, [UIActivityIndicatorView appearance]). For more information about appearance proxies, see Appearance Proxies.

使用外观代理(appearance proxy)来自定义你app里面的所有activity indicator的外挂。更多详情请看Appearance Proxies.

Style

The Style (activityIndicatorViewStyle) field represents the predefined style of the activity indicator. Use the style to specify one of two default colors: white or gray. You can also select a larger size for your indicator using the “Large White” style option.

Style域呈现了预定义的活跃指示器风格。使用style来选定两个默认颜色之一:白色或者灰色。你也使用“Large White(巨大的白色的)”风格选项为指示器选择一个更大的大小。

The Color (color) field allows you to specify a custom color for your indicator. This property takes precedence over any color set using the Style field. However, if your style is set to Large White, your activity indicator appears a larger size. Make sure your indicator is set to a different style option if you want to use the small indicator.

Color域允许你为你的指示器规定一个自定义颜色。这个属性优先于任何通过Style域设定的颜色。但是,如果style被设置为Large White,你的指示器显示为一个更大大小。如果你想使用一个小的指示器的话,确认你的指示器被设置为一个不同风格选项。(意思是说Large White 是白色,但不要为了用白色来选择那个选项,因为它会使指示器变大)

image: ../Art/uiactivityindicator_attributes_inspector_main_2x.png

Using Auto Layout with Activity Indicators

You can create Auto Layout constraints between an activity indicator and other UI elements.

你可以在activity indicator 和其他UI 元素之间创建自动布局约束。

Typically, activity indicators appear before a label or centered within a view. To align with a label, constrain Bottom Edges and Horizontal Space to the label with the standard value. To center within a view, add the Horizontal Center in Container and Vertical Center in Container constraints.

一般地,activity indicators在标签或者在一个视图中剧中前显示。与一个标签排列,用标准值约束底部边距和相对便签的水平空间。在Container 约束中增加一个Horizontal Center(水平居中) 和Vertical Center(垂直居中)来在一个视图中居中。

For general information about using Auto Layout with iOS views, see Using Auto Layout with Views.

Making Activity Indicators Accessible

Activity indicators are accessible by default. The default accessibility trait for an activity indicator is User Interaction Enabled. 

Activity indicators默认是可以访问的.默认的访问特性可以通过User Interaction 来设定。

If you have a label next to your activity indicator that describes the processing task in more detail, you might want to disable its accessibility with the isAccessibilityElement property so VoiceOver reads the label instead. Otherwise, VoiceOver reads “In progress” while the activity indicator is animating, and “Progress halted” while it is not.

如果你在activity indicator边上有标签来描述正在进行中的任务更多的细节,你大概想要用isAccessibilityElement属性来禁用,使得VoiceOver取而代之朗读标签的内容。否则,VoiceOver会在activity indicator还在旋转的时候读出"正在处理",停止旋转的时候读出"停止处理"。

VoiceOver will read only elements that are visible onscreen. If you enable the hidesWhenStopped property, VoiceOver might abruptly stop speaking when the animation finishes.

VoiceOver将只会读屏幕上可视的元素。如果激活了hidesWhenStopped(结束时隐藏)属性,VoiceOver很大可能在动画结束的时候突然停止发声。

For general information about making iOS views accessible, see Making Views Accessible.

Internationalizing Activity Indicators

Activity indicators have no special properties related to internationalization. However, if you use an activity indicator with a label, make sure you provide localized strings for the label.

Activity indicators没有与国际化相关的属性。但是,如果你和标签一起用的话,确认你为标签提供了本地化的描述。

For more information, see Internationalization and Localization Guide.

Debugging Activity Indicators

When debugging issues with activity indicators, watch for this common pitfall: 

Specifying conflicting appearance settings. The color property takes precedence over any color set using the activityIndicatorViewStyle property. However, if your style is set to Large White, your activity indicator appears a larger size with whatever custom color you set. Make sure your indicator is set to a different style option if you want to use the small indicator.

使用了冲突的外观设置。color属性比任何使用activityIndicatorViewStyle属性的设置有更高的优先级。但是,如果你的style被设置为Large White,你的activity Indicator无论你设置了什么自定义颜色都会显示了一个更大的大小。如果你想使用一个更小的指示器,确认你的指示器被设置为一个不同的选项。

Elements Similar to an Activity Indicator

The following element provides similar functionality to an activity indicator:

以下的元素提供了与activity indicator相似的功能:

Progress View. A class that represents a progress bar. Use this class instead of an activity indicator when your task takes a determinate amount of time. For more information, see Progress Views.

一个显示进程条的类。使用这个类取代activity indicator。

posted @ 2015-02-08 20:16  baaingSheep  阅读(434)  评论(0编辑  收藏  举报