Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue animating with 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 am doing wrong - any help would be appreciated please.

like image 667
RunLoop Avatar asked Oct 18 '22 21:10

RunLoop


1 Answers

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

The setup is a UIViewController which adds a header UIImageView and a UITableView to its own view in viewDidLoad. The animation is then added last to be on top of the other views. It seems the UITableView somehow modifies the zPositions of layers, so only after finally trying leftdoorView.layer.zPosition = 1000; and moving the actual animation to a separate selector executed 0.2 secs after viewDidLoad did the animation show properly.

like image 82
RunLoop Avatar answered Nov 02 '22 07:11

RunLoop