开发者

Can't undo a scale transform without undoing a rotation transform

开发者 https://www.devze.com 2023-01-21 00:18 出处:网络
Here\'s a follow up to a previous question.My code below animates a square by scaling it and rotating it.It does this by making a rotation transform and adding a scale transform to it.That works fine.

Here's a follow up to a previous question. My code below animates a square by scaling it and rotating it. It does this by making a rotation transform and adding a scale transform to it. That works fine. When it's done, it calls throbReset. I used to have throbReset just set self's transform to a CGAffineTransformMakeScale and that would unscale it, but would also unrotate it. So I tried starting with the current transform and adding the unscale to it, but now it doesn't do anything (visible).


CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor];
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDelegate:self];
 [UIView setAnimationDuration:0.5f];
 [UIView setAnimationDidStopSelector:@selector(throbReset:context:)];
//  [[self layer] setFillMode:kCAFillModeForwards]; // apparently not needed
 CGAffineTransform xForm = CGAffineTransformMakeScale(2.0, 2.0);
 xFor开发者_JAVA技巧m = CGAffineTransformRotate(xForm, M_PI / 4);
 [self setTransform:xForm];
 [[self layer] setBackgroundColor:color];
 [UIView commitAnimations];
}

- (void)throbReset:(NSString *)animationID context:(void*)context {
 NSLog(@"-%@:%s fired", [self class], _cmd);
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:2.0];
 CGAffineTransform xForm = [self transform];
 xForm = CGAffineTransformScale(xForm, 1.0, 1.0);
 [self setTransform:xForm];
 [UIView commitAnimations];
}


You are just scaling to the same size since you are basically saying take the current transform and scale it 1:1 on X and 1:1 on Y. You might want to do 0.5,0.5 instead of 1.0,1.0 in your second method.

CGAffineTransform xForm = [self transform];
xForm = CGAffineTransformScale(xForm,0.5, 0.5);

Keep in mind when you add the rotation to do it in reverse order, so rotate then scale. This would be more important if you involved a translation but in this case would probably work either way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号