How do i rotate an image inside a drawn polygon

廉价感情. 提交于 2019-12-25 09:36:35

问题


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.

Here is my code:

-(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.


回答1:


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

polyView.transform = CGAffineTransformMakeRotation(M_PI_4);

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

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.



来源:https://stackoverflow.com/questions/22997699/how-do-i-rotate-an-image-inside-a-drawn-polygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!