How to change UIView zPosition?

I do not understand how to change the zPosition of the view, I am trying to do this, but nothing happens:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease];
    view.backgroundColor = [UIColor blackColor];
    view.layer.zPosition = -400;
    [self.view addSubview:view];
}

The CALayer document does not say anything before using this property. Does anyone know what I am missing?

Thanks, Vincent.

+3
source share
2 answers

zPosition , , . , , , . , , .

, , , zPosition. , Z, , . Z, , . , , .

- , . .

+11

zPosition CALayer UIView.transitionWithView().

var isFirstViewOnTop = true
func switchCards() {
    self.isFirstViewOnTop = !self.isFirstViewOnTop

    UIView.transitionWithView(
        self,
        duration: 0.25,
        options: .TransitionCrossDissolve,
        animations: { () -> Void in
            self.firstView.layer.zPosition = self.isFirstViewOnTop ? 1 : 0
            self.secondView.layer.zPosition = !self.isFirstViewOnTop ? 1 : 0
        },
        completion: nil
    )
}
0

Source: https://habr.com/ru/post/1760878/


All Articles