Transform.Translation problem on rotation

Posted by eco_bach on Stack Overflow See other posts from Stack Overflow or by eco_bach
Published on 2010-06-18T13:39:34Z Indexed on 2010/06/18 13:43 UTC
Read the original article Hit count: 323

I am using the following to scale and reposition a UIView layer when the device rotates to landscape.

 [containerView.layer setValue:[NSNumber numberWithFloat: 0] forKeyPath: @"transform.translation.x"];
 [containerView.layer setValue:[NSNumber numberWithFloat: 0] forKeyPath: @"transform.translation.y"];    
 [containerView.layer setValue:[NSNumber numberWithFloat: 1] forKeyPath: @"transform.scale.x"]; //[NSNumber numberWithInt:1]
 [containerView.layer setValue:[NSNumber numberWithFloat: 1] forKeyPath: @"transform.scale.y"];

and then the folowing when rotating back to portrait

 [containerView.layer setValue:[NSNumber numberWithFloat: -75] forKeyPath: @"transform.translation.x"];
 [containerView.layer setValue:[NSNumber numberWithFloat: 0] forKeyPath: @"transform.translation.y"];    
 [containerView.layer setValue:[NSNumber numberWithFloat: .7] forKeyPath: @"transform.scale.x"]; //[NSNumber numberWithInt:1]
 [containerView.layer setValue:[NSNumber numberWithFloat: .7] forKeyPath: @"transform.scale.y"];

The problem is that after rotaing back to portrait, the layer is 'travelling' ie the x,y offset are gradually changing(increasing x, decreasing y). Scale seems fine (ie doesn't increment, decrement on repeated rotations)

Can anyone suggest a proper solution?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about best-practices