如何在绘制的多边形内旋转图像 [英] How do i rotate an image inside a drawn polygon

查看:117
本文介绍了如何在绘制的多边形内旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名初学者程序员,这是我的第一个应用程序(我仍在学习中).我已经在地图视图上覆盖了一个多边形.我已将其填充颜色设置为图像,因为我正在尝试将图像与卫星图像进行匹配.我想旋转它,以使多边形内容与地图匹配.可以旋转图像吗?如果没有,是否有一种更简单的方法可以将图像叠加到我可以使用的地图视图上.

I am a beginner programmer and this is my first app(I am still learning). I have overlaid a polygon onto a map view. I have set its fill color to an image because I'm trying to match an image to a satellite picture. I want to rotate it so that the polygon contents match the map. Is it possible to rotate the image? If not, is there an easier way to overlay an image onto a map view that I could use.

这是我的代码:

-(MKOverlayView*)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay {

MKPolygonView *polyView = [[MKPolygonView alloc] initWithOverlay:overlay];
polyView.strokeColor = [UIColor whiteColor];
polyView.fillColor = [UIColor  colorWithPatternImage:[UIImage imageNamed:@"Campus-map labels.jpg"]];

return polyView;
}

这是我要尝试的操作,如果有帮助的话:

Here's what I'm trying to do, if it helps:

http://i.stack.imgur.com/x53HU.jpg

以红色圈出的道路应匹配.我知道多边形的位置不正确-这是为了说明多边形如何旋转.

The road which is circled in red should match up. I know that the polygon isn't in the right position -- this is to illustrate how the polygon needs to be rotated.

推荐答案

您可以修改polyView对象的transform属性.例如:

You can modify the transform property of the polyView object. For example:

polyView.transform = CGAffineTransformMakeRotation(M_PI_4);

polyView.transform = CGAffineTransformMakeRotation(M_PI_4);

将沿顺时针方向将多边形旋转pi/4弧度(45度).

will rotate the polygon by pi/4 radians (45 degrees), in a clockwise direction.

您可能需要更改多边形的center属性才能获得所需的效果. center属性确定围绕其旋转变换的旋转中心.

You might need to change the polygon's center property to get the effect you want. The center property determines the center of rotation around which the transform rotation takes place.

这篇关于如何在绘制的多边形内旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆