Maintaining last stage when rotating through CATransform3DIdentity
- by Mikhail Naimy
Hi. i am rotating imageview through following code.it rotates fine..but when i rotate again , Imageview goes to previous angle( which is in initial stage) and then it rotates...any one can help in this?rotationTransform has been declared as CABasicAnimation* rotationAnimation in .h file....
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
startTouchPosition = [touch locationInView:self.view];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [[event allTouches] anyObject];
location = [touch locationInView:self.view];
currentLocationRadians = atan2f(location.y - self.view.frame.size.height/2, location.x - self.view.frame.size.width/2);
lastLocationRadians = atan2f(startTouchPosition.y - self.view.frame.size.height/2, startTouchPosition.x - self.view.frame.size.width/2);
rotationTransform = CATransform3DIdentity;
rotationTransform = CATransform3DRotate(rotationTransform, currentLocationRadians-lastLocationRadians + rad, 0.0, 0.0, 1.0);
_imgview.layer.transform = rotationTransform;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
rotationTransform = _imgview.layer.transform;
}