IOS7过渡之---Layout and Appearance 布局和外观

来源:互联网 发布:战斗行动预测数据库 编辑:程序博客网 时间:2024/05/02 04:59

IMPORTANT

This is a preliminary document for an API or technology in development. Although this document has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only by registered members of the applicable Apple Developer program. Apple is supplying this confidential information to help you plan for the adoption of the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be tested with final operating system software and final documentation. Newer versions of this document may be provided with future seeds of the API or technology.

要:这篇文章是初步文稿,内容是开发的API和技术。虽然这个文稿已经被仔细审核过,但是这不是最终稿。这些信息是只有苹果开发者才能知道的机密。苹果提供这些机密信息来帮助你来计划用什么技术和编程接口。这些信息可能会变化,软件实现根据这个文档应用是用来测试最终的系统和文档的。这个文档更新的版本会在未来提供。


iOS 7 brings several changes to how you lay out and customize the appearance of your UI. The changes in view-controller layout, tint color, and fonts affect all the UIKit objects in your app.

iOS 7带来了几样变化:如何布局,如何定制你的UI外观。这些变化主要在视图控制器的布局、TINT颜色、影响UIKIT所有元素的字体。

Using View Controllers

使用视图控制器

In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify the layout of each edge of its view.

在IOS 7,视图控制器使用全屏的布局。同时,IOS 7给你更多的细致的控制,控制视图控制器的怎么布局它的视图们。特别重要的是,全屏的布局概念已经细化到可以使视图控制器指定到每个UI元素的边。

The wantsFullScreenLayout view controller property is deprecated in iOS 7. If you currently specifywantsFullScreenLayout = NO, the view controller may display its content at an unexpected screen location when it runs in iOS 7.

 wantsFullScreenLayout 属性在IOS 7里面已经废弃。如果你现在还用它,视图控制器可能会把内容显示在意想不到的屏幕的位置,在IOS 7下。

To adjust how a view controller lays out its views, UIViewController provides the following properties:

  • edgesForExtendedLayout

    The edgesForExtendedLayout property uses the UIExtendedEdge type, which specifies each of a rectangle’s four edges, in addition to specifying none and all.

    Use edgesForExtendedLayout to specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is UIRectEdgeAll.

  • extendedLayoutIncludesOpaqueBars

    If your design uses opaque bars, refine edgesForExtendedLayout by also setting theextendedLayoutIncludesOpaqueBars property to NO. (The default value ofextendedLayoutIncludesOpaqueBars is YES.)

  • automaticallyAdjustsScrollViewInsets

    If you don’t want a scroll view’s content insets to be automatically adjusted, setautomaticallyAdjustsScrollViewInsets to NO. (The default value ofautomaticallyAdjustsScrollViewInsets is YES.)

视图控制器提供以下属性来修改控制器内布局视图:

1.edgesForExtendedLayout 这个属性指定矩形的四个边,可以一个边都不设置,也可以全设置。使用这个属性来指定每个视图的边应该是可扩展的、无关BAR透明度的。默认的,这个属性是UIRectEdgeAll 

2.  extendedLayoutIncludesOpaqueBars  如果你的设计使用了不透明BAR,在设置edgesForExtendedLayout时设置它为NO

3.automaticallyAdjustsScrollViewInsets如果你不想滚动视图的内嵌视图被自动布局调整,设置 setautomaticallyAdjustsScrollViewInsets 为NO


In iOS 7, view controllers can support custom animated transitions between views. In addition, you can use iOS 7 APIs to support user interaction during an animated transition. To learn more, seeUIViewControllerAnimatorTransitioning Protocol Reference and UIViewControllerInteractiveTransitioning Protocol Reference.

在IOS 7,视图控制器支持自定义的视图间动画转换。另外,你可以用IOS7 API来支持动画交互。要了解更多,请看UIViewControllerAnimatorTransitioning 协议和  UIViewControllerInteractiveTransitioning Protocol Reference.

iOS 7 gives view controllers the ability to adjust the style of the status bar while the app is running. To enable this behavior, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value YES. A good way to change the status bar style dynamically is to implementpreferredStatusBarStyle and—within an animation block—update the status bar appearance and callsetNeedsStatusBarAppearanceUpdate.

IOS 7给视图控制器在应用运行时改变状态条风格的能力。要增加这个行为,只要修改 info.plist 并且修改UIViewControllerBasedStatusBarAppearance属性为YES即可。正确的动态改变状态条风格的方式是实现preferredStatusBarStyle ,也可以在动画的BLOCK中,然后更新状态条刷新调用 callsetNeedsStatusBarAppearanceUpdate


Using Tint Color

使用着色

In iOS 7, tint color is a property of UIView. iOS 7 apps often use a tint to define a key color that indicates interactivity and selection state for elements throughout the app.

在IOS 7里面,tint color是 UIView 的一个属性。IOS 7应用里所有UI元素经常使用一个着色来定义关键颜色比如这个颜色表明是互动的或者是选中状态的。

When you specify a tint for a view, the tint is automatically propagated(繁衍) to all subviews in the view’s hierarchy. Because UIWindow inherits from UIView, you can specify a tint color for the entire app by setting the window’s tint property using code like this:

  1. window.tintColor = [UIColor purpleColor];

If you don’t specify a tint for the window, it uses the system default color.

当你指定一个UIVIEW的tint颜色的时候,这个着色自动的应用到所有它的子视图。因为UIWindow继承了UIView,你可以指定WINDOW的tint颜色就可以啦。

如果你为window 设置这个值,它会使用系统的默认颜色。

By default, a view’s tint color is nil, which means that the view uses its parent’s tint. It also means that when you ask a view for its tint color, it always returns a color value, even if you haven’t set one.

默认的视图TINT 颜色是空,这就意味着它会使用它的父视图的TINT颜色。也就是说当你查看VIEW的TINT COLOR时候,它总是会返回一个值,即使它没有被设置过。

In general, it’s best to change a view’s tint color while the view is offscreen. To cause a view to revert to using its parent’s tint, set the tint color to nil.

一般情况下,在视图还没在屏幕上的时候来修改视图的TINT 颜色。如果要视图恢复到它的父视图的TINT 颜色,设置TINT颜色为空即可。 

IMPORTANT

Setting tint color using the appearance proxy APIs is not supported in iOS 7.

设置TINT颜色使用第三方的API,是不会在IOS 7上起作用的。

When an alert or action sheet appears, iOS 7 automatically dims the tint color of the views behind it. To respond to this color change, a custom view subclass that uses tintColor in its rendering should overridetintColorDidChange to refresh the rendering when appropriate.

当警告框出来的时候,IOS 7自动把警告框后的视图的TINT COLOR加重。为应对这个颜色的变化,自定义视图如果在渲染代码里面使用了 tintColor ,需要重新 tintColorDidChange 来在合适的时候刷新渲染。

NOTE

In iOS 6, tintColor tinted the background of navigation bars, tab bars, toolbars, search bars, and scope bars. To tint a bar background in iOS 7, use the barTintColor property instead.

注:

在IOS 6,tintColor属性在导航条,TAB条,工具条,搜索条,范围条上已经用了。在IOS 7里,需要用 barTintColor 属性来代替。

Using Fonts

 使用字体

iOS 7 introduces Dynamic Type, which makes it easy to display great-looking text in your app.

IOS 7引入了动态类型,这意味着更便捷的在你的应用里面显示好看的文字了。

A message at the smallest text size

image: ../Art/mail_message_7_2x.png

A message at the largest non Accessibility text size

image: ../Art/message_large_2x.png

When you adopt Dynamic Type, you get:

  • Automatic adjustments to weight, letter spacing, and line height for every font size.

  • The ability to specify different text styles for semantically distinct blocks of text, such as BodyFootnote, or Headline1.

  • Text that responds appropriately to changes in both the Dynamic Type and accessibility settings for user-specified text sizes.

当你选择动态类型,你会得到:

1.为每个字体自动调整重量,单词间隔,以及线条高度。

2.对不同文本块指定不同的文字STYLE,比如BODY , FOOT NOTE 或者 HEADLINE1

3.文字根据用户设置的动态类型和辅助设置会恰当的变化展示。

To take advantage of these features, use the UIFont method preferredFontForTextStyle to get a font, instead of specifying font names or sizes. iOS 7 optimizes this font for maximum legibility at every size.

想要使用这个功能的话,使用 UIFont 的 preferredFontForTextStyle 属性来得到一个字体,替换以前的指定字体名字和大小的方式。IOS 7为这些每个尺寸的字体都做了最大清晰度优化。