문제

I have a ball class which is composed by an UIImage I draw on the screen. I have 2 floats to get poistion of the UIImage, x and y so I made 2 getters to have the position:

-(float) getX { return self.center.x; }
-(void) setX: (float)x_{ x = x_; }

-(float) getY { return self.center.y; }
-(void) setY: (float)y_{ y = y_; }

that returns me "Request for member 'center' in something not a structure or union"

But self.center.x normally returns a float...I don't understand...

도움이 되었습니까?

해결책

UIImage doesn't have a center property. You're probably thinking of things that descend from UIView. The view that displays an image is a UIImageView — that would have a center property.

UIImages also don't inherently have a position, so there's no comparable centre, but if you do something like:

CGPointMake(image.size.width*0.5f, image.size.height*0.5f);

You'll get a location in the middle of the image, relative to the image itself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top