现在的位置: 首页 > 综合 > 正文

UIView中文部分翻译

2013年08月28日 ⁄ 综合 ⁄ 共 4787字 ⁄ 字号 评论关闭

UIView本来想翻译完的,可是翻着翻着就懒了。有时间再翻翻。

UIView Class Reference

Inherits from    
UIResponder : NSObject
Conforms to    
NSCoding
NSObject (NSObject)
Framework    
/System/Library/Frameworks/UIKit.framework
Availability    
Available in iOS 2.0 and later.
Companion guide    
View Programming Guide for iOS
Declared in    
UIPrintFormatter.h
UITextField.h
UIView.h
Related sample code    
iPhoneCoreDataRecipes
iPhoneMixerEQGraphTest
MoveMe
Touches
UICatalog

OverView
UIView类定义了在一个屏幕上一个矩形的区域并且定义了一些管理在这个区域内内容的接口。在运行时,这个view对象处理在这个区域内的内容的渲染,也提供处理内容的接口。
UIView类本身为带背景颜色的填充区域提供基本的动作。
因为view对象是你的程序和用于互动的主要途径,这些view有一系列的责任。
绘画和动画
布局和子view的管理
一个view可以包含0或者多个子view
每一个view都定义他自己相对于他的父view的默认resizing行为
一个可以手动改变他的size和position。
事件处理:
一个view是一个响应器并且处理触摸事件和别的在UIResponder类中定义的事件。
views能够用 addGestureRecognizer: 方法去安装手势识别器去出去一般的手势。

一个父view可能包含任意数目的子view,但是每一个子view只能有且只有一个superview(负责合适的放置它的子view的位置)。
View的几何性质Frame,bounds,center。frame的size接口和bounds的矩形是绑定一起的,所以改变任何矩形的size都会更新他们两个的size。
Creating a View
用代码编程创建一个view,可以用下面类似的代码:
CGRect  viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
为了给你的view添加一个子view,你可以用adsSubView:方法。这个addSubView:方法放置特定的view到别的兄弟view的最高层。你可以制定一个子view
的Z-次序的相对管理,通过用 insertSubview:aboveSubview: and insertSubview:belowSubview: 去添加它的时候。你可以交换已经存在的子views的位置
通过用exchangeSubviewAtIndex:withSubviewAtIndex:方法。
当创建一个view的时候,去适当的赋一个合适的值到 autoresizingMask属性以确保这个view可以重新正确的赋值size。view自动赋值size主要发生在当你程序的方向改变时。
但是它也经常发生在别的时候。比如调用setNeedsLayout 去强制更新它的布局的时候。
The View Drawing Cycle
The UIView class uses an on-demand drawing model for presenting content. When a view first appears on the screen, the system asks it to draw its content. If you never change the view’s content, the view’s drawing code may never be called again.If you do change
the view’s content, you do not redraw the view’s contents directly. Instead, you invalidate the view using either the setNeedsDisplay or setNeedsDisplayInRect: method and let the system redraw its contents later.
Note: Changing a view’s geometry does not automatically cause the system to redraw the view’s content.

For custom UIView subclasses, you typically override the drawRect: method of your view and use that method to draw your view’s content. There are also other ways to provide a view’s content, such as setting the contents of the underlying layer directly, but
overriding drawRect: is the most common technique.

Content Modes
The content mode of a view is applied whenever you do the following:

Change the width or height of the view’s frame or bounds rectangles.
Assign a transform that includes a scaling factor to the view’s transform property.
By default, the contentMode property for most views is set to UIViewContentModeScaleToFill,which causes the view’s contents to be scaled to fit the new frame size。As you can see from the figure, not all content modes result in the view’s bounds being filled
entirely, and those that do may distort that content.
其中使用UIViewContentModeScaleToFill会使图片变形Distort

Stretchable Views
 The stretchable area you specify can allow for stretching along one or both axes of the view. Of course, when stretching a view along two axes, the edges of the view must also define a repeatable pattern to avoid any distortion.
You specify the stretchable portion of a view using the contentStretch property.
 Stretchable areas are only used when the content mode would cause the view’s content to be scaled. This means that you stretchable views are supported only with the UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, and UIViewContentModeScaleAspectFill
content modes. If you specify a content mode that pins the content to an edge or corner (and thus does not actual scale the content), the view ignores the stretchable area.

Built-In Animation Support
To perform an animation for one of these animatable properties, all you have to do is:
Tell UIKit that you want to perform an animation.
Change the value of the property.
Among the properties you can animate on a UIView object are the following:

frame - You can use this to animate position and size changes for the view.
bounds - Use this to animate changes to the size of the view.
center - Use this to animate the position of the view.
transform - Use this to rotate or scale the view.
alpha - Use this to change the transparency of the view.
backgroundColor - Use this to change the background color of the view.
contentStretch - Use this to change how the view’s contents stretch.
In addition to the animations you create using UIKit classes, you can also create animations using Core Animation layers. Dropping down to the layer level gives you much more control over the timing and properties of your animations.
here are two different ways to initiate animations:

In iOS 4 and later, use the block-based animation methods. (Recommended)
Use the begin/commit animation methods.
The block-based animation methods (such as animateWithDuration:animations:) greatly simplify the creation of animations. With one method call, you specify the animations to be performed and the options for the animation. However, block-based animations are
available only in iOS 4 and later. If your application runs on earlier versions of iOS, you must use the beginAnimations:context: and commitAnimations class methods to mark the beginning and ending of your animations.

Methods to Override

When subclassing UIView, there are only a handful of methods you should override and many methods that you might override depending on your needs

抱歉!评论已关闭.