圖層有什麼用?添加圖層可以做什麼,為什麼要考慮圖層? (What are Layers good for? What could I do with adding an Layer, and why should I think about Layers?)


問題描述

圖層有什麼用?添加圖層可以做什麼,為什麼要考慮圖層? (What are Layers good for? What could I do with adding an Layer, and why should I think about Layers?)

I am wondering what makes Layers different from Views, when every View comes along with it's own Layer. Maybe I am wrong with that. But then: What are these Layers good for?

Like I understand it, I would use an UIView to group elements in my GUI. I could also use that UIView to position things over other things. So where come Layers into place here?

Should I think of them just as the z-index like in HTML / CSS? Are they just interesting for Core Animation stuff?


參考解法

方法 1:

Compared to UIVIews, CALayers are

  • lightweight
  • filled with timing information for animation
  • Some things are harder to draw, like text (esp. unicode).

If you have less than 20 or so of them, it probably doesn't matter.  If you have complicated animation needs, or just a ton of layers to draw, you may benefit from using CALayers instead.

方法 2:

On the iPhone, there's not a significant performance difference between using UIViews and CALayers, in my experience.  The Mac is a different story, with NSViews being significantly more heavyweight.

Dealing with CALayers (or at least a view's layer backing) is sometimes necessary for complex animations, particularly keyframe animations or movement along paths.

Additionally, CALayers can be used to create platform-independent (Mac and iPhone) custom user interfaces.  UIViews are very different from NSViews, but CALayers are identical between the iPhone and Mac OS X Leopard (aside from a few properties that are missing on the iPhone).  I've used CALayers to share UI code between an iPhone application and its Mac counterpart.

(by ThanksamattnBrad Larson)

參考文件

  1. What are Layers good for? What could I do with adding an Layer, and why should I think about Layers? (CC BY-SA 3.0/4.0)

#iphone #core-animation






相關問題

iPhone 3.0 MPMoviePlayerController 在屏幕上顯示視頻播放器的等待時間長有問題嗎? (Problem with iPhone 3.0 MPMoviePlayerController long wait time to display the video player on screen?)

將 NavigationBar 背景更改為圖像 (Changing the NavigationBar background to image)

如何將以下行添加到我的 plist 文件中? (How can I add the following lines to my plist file?)

iPhone SDK:檢查 UITableView 中每個對象的 ID 號並相應地更改徽章號 (iPhone SDK: Checking the ID number for each object in a UITableView and change the badge number accordingly)

無法在不崩潰的情況下設置 ABPeoplePickerNavigationController 的 addressBook 屬性 (Can't set the addressBook property of ABPeoplePickerNavigationController without crashing)

嵌套 XML 示例? (Nested XML Example?)

提交應用程序 - 添加本地化,但我的語言未列在組合框中? (Submitting app - Add Localizations, but my language is not listed in the combo box?)

如何從移動瀏覽器直接訪問移動設備的硬件功能 (How to gain direct access to the hardware capabilities of mobile devices from mobile browsers)

Cocos2d 中的粒子碰撞檢測 (Collision detection with particles in Cocos2d)

捕捉返回按鈕導航事件 (Catching back button navigation event)

iphone初學者問題:畫一個矩形。我究竟做錯了什麼? (Beginner iphone question: drawing a rectangle. What am I doing wrong?)

帶有 UITableView 的 UIPopoverController (UIPopoverController with UITableView)







留言討論