Invoking an animation using CATransform3DRotate

My code is below, but the animation just happens instantly, i.e. the view is no longer visible:

UIView *leftDoorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width /2, self.view.bounds.size.height)]; leftDoorView.backgroundColor = [UIColor greenColor]; leftDoorView.layer.anchorPoint = CGPointMake(0.0, 0.5); [self.view addSubview:leftDoorView]; leftDoorView.center = CGPointMake(0.0, self.view.bounds.size.height/2.0); //compensate for anchor offset CATransform3D transform = CATransform3DIdentity; transform.m34 = -1.0f/500.0; transform = CATransform3DRotate(transform, M_PI_2, 0, 1, 0); [UIView animateWithDuration:1.0 animations:^{ leftDoorView.layer.transform = transform; }]; 

Not sure what I'm doing wrong - any help would be appreciated please.

+5
source share
1 answer

The problem turned out to be for the zPositions of layers of other views - most likely caused by a UITableView in the hierarchy of views.

Customization is a UIViewController that adds the UIImageView and UITableView title to its own view in viewDidLoad. Then the animation is added last to be on top of other views. It seems that the UITableView modifies the zPositions of the layers somehow, so only after you finally try leftdoorView.layer.zPosition = 1000; and move the actual animation to a separate selector, executed 0.2 seconds after viewDidLoad correctly rendered the animation.

+3
source

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


All Articles