iOS - 基于X,Y方向旋转UIImageView
问题描述:
我已经将UIView作为包含图标(UIImageView),名称(UILabel)和ID(UILabel)的头像对象进行了子类化。根据X,Y坐标的方向,我想让图标旋转。例如,说orientation.X = 1和orientation.Y = 1会给45度角。 X和Y可以是-1和1之间的任何值。iOS - 基于X,Y方向旋转UIImageView
我不知道它是如何在数学上计算的,也没有可可API要求它。任何想法从哪里开始?
答
用于平滑我增加了一个动画:
- (void)rotateView:(UIView *)view withDuration:(NSTimeInterval)duration andRadians:(CGFloat)radians
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
CGAffineTransform transform = CGAffineTransformMakeRotation(radians);
view.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
编辑:
您需要创建自己的旋转矩阵其他角度。
读here如何在Objective-C创建一个自定义的仿射变换
希望这有助于。
我不想让图像绕中心旋转,因为它将图像拧紧 – KaiserJohaan
我添加了我的帖子,希望它有帮助。 – Justin