How to set iPhone UIView z index?

2019-01-02 21:26发布

I want to move one view on top of another, how can I know the z index of the view, and how to move on to top?

7条回答
可以哭但决不认输i
2楼-- · 2019-01-02 22:30

You can use the zPosition property of the view's layer (it's a CALayer object) to change the z-index of the view.

theView.layer.zPosition = 1;

As Viktor Nordling added, "big values are on top. You can use any values you want, including negative values." The default value is 0.

You need to import the QuartzCore framework to access the layer. Just add this line of code at the top of your implementation file.

#import "QuartzCore/QuartzCore.h"
查看更多
登录 后发表回答