使用一根手指触摸在中心旋转图像
我想使用一根手指触摸在中心点上旋转下面的图像...
并且当我使用触摸旋转图像时,我想用标签显示图像的值。
我已经完成了图像旋转,但问题是如何根据旋转设置图像的值。
旋转角度增加,因此我无法设置该值。
有人可以帮助我吗?
代码如下
float fromAngle = atan2(firstLoc.y-imageView.center.y,
firstLoc.x-imageView.center.x);
NSLog(@"From angle:%f",fromAngle);
float toAngle = atan2( currentLoc.y-imageView.center.y,
currentLoc.x-imageView.center.x);
NSLog(@"to Angle:%f",toAngle);
// So the angle to rotate to is relative to our current angle and the
// angle through which our finger moved (to-from)
float newAngle =angle+(toAngle-fromAngle);
NSLog(@"new angle:%.2f",newAngle);
CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle);
imageView.transform=cgaRotate;
angle = newAngle;
有人可以帮助我吗?
I want to rotate the below image on a center point using one finger touch...
And i want to display the value of the image with the label when I rotate the image using touch.
I have done the image rotation but the problem is that how to set the value of the image according to rotation.
The angle of the rotation is increase so i can not set the value.
Can any one help me?
The code is below
float fromAngle = atan2(firstLoc.y-imageView.center.y,
firstLoc.x-imageView.center.x);
NSLog(@"From angle:%f",fromAngle);
float toAngle = atan2( currentLoc.y-imageView.center.y,
currentLoc.x-imageView.center.x);
NSLog(@"to Angle:%f",toAngle);
// So the angle to rotate to is relative to our current angle and the
// angle through which our finger moved (to-from)
float newAngle =angle+(toAngle-fromAngle);
NSLog(@"new angle:%.2f",newAngle);
CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle);
imageView.transform=cgaRotate;
angle = newAngle;
Can any one help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不完全确定你在追求什么;但试试这个代码。
如果您创建一个名为“Rotation”的新的基于视图的应用程序项目,并将 RotationViewController.h 和 .m 中的代码替换为以下内容,您将获得一个绿色块,您可以使用计算来旋转该块。您可以将绿色块 UIView 替换为 UIImageView 或您想要旋转的任何其他内容。
RotationViewController.h
RotationViewController.m
Wasn't totally sure what you were after; but try out this code.
If you create a new View-based Application project called 'Rotation' and replace the code in RotationViewController.h and .m for the following you'll get a green block that you can rotate using your calculations. You can replace the green block UIView with your UIImageView, or anything else you want to spin.
RotationViewController.h
RotationViewController.m