iphone - CGAffineTransform Rotation 拉伸(stretch)了我的图像,我做错了什么?

标签 iphone objective-c transform

我有一张图片显示 map 上的北方方向。如果找到新航向,则 CoreLocation 会更新此图像。它也被放置在正确的位置,我使用以下代码:

locateMeView.transform = CGAffineTransformMakeRotation(([CoreLocationController sharedInstance].heading - 45) * M_PI / 180);
CGRect frame = locateMeView.frame;
CGPoint pos = [MapClass vectorForLocation:[CoreLocationController sharedInstance].location mapCenter:curLocation zoom:curZoom];
frame.origin.x = (int)(self.view.bounds.size.width/2 + pos.x - frame.size.width / 2);
frame.origin.y = (int)(self.view.bounds.size.height/2 + pos.y - frame.size.height / 2);
frame.size.width = 24;
frame.size.height = 24;
locateMeView.frame = frame;

CoreLocationController 是一个存储普通 CoreLocation 更新的类。 MapClass 将我的 map 上的纬度/经度坐标转换为 x/y 坐标。图像的位置是正确的,但旋转会导致奇怪的效果。对于 0 en M_PI,图像是正确的,但在这些图像之间,图像被拉伸(stretch),就好像它也绕 z 轴旋转一样,在 M_PI/2 和 3 * M_PI/2 处,它完全消失了。有人可以解释发生了什么以及我做错了什么吗?

最佳答案

我发现出了什么问题(无论如何或多或少)。使用 transform 属性时,不允许(无论出于何种原因)通过更改框架来更改位置,您必须使用 center 属性。所以最后的代码是:

CGPoint pos = [MapClass vectorForLocation:[CoreLocationController sharedInstance].location mapCenter:curLocation zoom:curZoom];
locateMeView.transform = CGAffineTransformMakeRotation(([CoreLocationController sharedInstance].heading - 45) * M_PI / 180);
locateMeView.center = CGPointMake(int)(self.view.bounds.size.width/2 + pos.x), (int)(self.view.bounds.size.height/2 + pos.y));

希望有同样问题的人能找到我的答案。

关于iphone - CGAffineTransform Rotation 拉伸(stretch)了我的图像,我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4916416/

相关文章:

iphone - NSInteger != 无

iphone - 使用 MagicalRecord 使用当前实体创建新实体

iphone - YouTube 嵌入 UIWebView 的问题

objective-c - 混合 NSXPCConnection 和 xpc C API

css - 旋转框架但不旋转图像

Jquery .css() 方法不适用于 css 函数

html - 旋转div后如何设置边距自动适合顶部

iphone - Three20 和 iOS 4

iphone - 如何将功能或设计委托(delegate)给其他 UIViewController

ios - 如何使用 Superpowered 从麦克风进行实时音调转换?