How do I bring a CALayer sublayer
to the front of all sublayers, analogous to -[UIView bringSubviewToFront]
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Right code here
I don't think such methods exist, but it's easy to roll your own.
I'm curious why none of these answers mention the zPosition attribute on CALayer. Core Animation looks at this attribute to figure out layer rendering order. The higher the value, the closer it is to the front. These answers all work as long as your zPosition is 0, but to easily bring a layer to the front, set its zPosition value higher than all other sublayers.
Swift 4 version.
Idea that layer itself has
bringToFront
andsendToBack
methods.Usage:
Create a category of CALayer like this:
This is variation of @MattDiPasquale's implementation which reflects UIView's logic more precisely:
Note: if you don't use ARC, you may wish to add
[layer retain]
at top and[layer release]
at bottom of both functions to make surelayer
is not accidentally destructed in a case it has retain count = 1.