使用UIView更改框架来旋转UIImageView动画更改它的尺寸
问题描述:
当第一次旋转UIImageView并将其动画框架时,我目前遇到了麻烦。只要我开始将它的框架动画到target_position,我的图像就会改变它的大小。它得到更广泛和更高(根据旋转角度)使用UIView更改框架来旋转UIImageView动画更改它的尺寸
我目前使用的旋转的代码是:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (!isAnimating) {
isAnimating = YES;
UITouch *t = [[touches allObjects] lastObject];
float angle = atan2([t locationInView:self.view].y - player.frame.origin.y, [t locationInView:self.view].x - player.frame.origin.x) * 180/M_PI;
NSLog(@"Angle: %f", angle);
CGAffineTransform cgCTM = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(angle));
[player setTarget_position:CGRectMake([t locationInView:self.view].x, [t locationInView:self.view].y, player.image.size.width-angle, player.image.size.height+angle)];
[UIView beginAnimations:@"rotatePlayer" context:nil];
[UIView setAnimationDuration:2];
player.transform = cgCTM;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(playerFinishedRotating)];
[UIView commitAnimations];
}
}
旋转本身运行正常。这是playerFinishedRotating函数的代码:
- (void)playerFinishedRotating {
[UIView beginAnimations:@"rotatePlayer" context:nil];
[UIView setAnimationDuration:3];
[player setFrame:[player target_position]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(playerFinishedAnimating)];
[UIView commitAnimations];
}
对我来说,它是一种合乎逻辑的,而旋转的我UIImageVie改变它的大小。但我坚持如何用给定的数据(旋转角度f.e.)来调整我的target_position帧的宽度和高度值。
我不是一个数学天才,所以对于其他人的答案可能是显而易见的,但对我来说这不是:(
希望有人能帮助,如果您还有其他问题,请LEVE评论。