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 uni开发者_Python百科on"
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.
精彩评论