setAnchorPoint for UIImage?

2019-04-08 02:04发布

问题:

All,

This is probably very basic, but I cannot find an answer that works for me.
Simple enough -- I want to rotate an image around an endpoint, not the center. I know that all I really need is to be able to set the anchor point of the image and then apply the transform.

I cannot, however, figure out how to set the anchor point of the image (or should it be an UIImageView?)

UIImageView * imgv = nil;
UIImage * image;

imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"greenbar.png"]];
image = [imgv image];
image.layer.anchorPoint =  CGPointMake(0.5, 1.0);***-- Request for member 'layer' in something not a structure or union.***
imgv.image.layer.anchorPoint = CGPointMake(0.5, 1.0); ***-- Request for member 'layer' in something not a structure or union.***
imgv.layer.anchorPoint = CGPointMake(0.5, 1.0);  ***-- Accessing unknown 'anchorPoint' component of a property.***

This is driving me crazy, so please help! :)

Thank you!

:bp:

回答1:

layer is imageView property so the following line should be correct:

imgv.layer.anchorPoint = CGPointMake(0.5, 1.0);

The reason you get this error may be that you need to import quartzcore header:

#import <QuartzCore/QuartzCore.h>