Property 'center' not found on object of type UIImage *

1.3k views Asked by At

I have a defined a view on my controller called FirstView. I have this in my -(void)move method:

-(void)move
{
 head = CGPointMake(head.center.x + X, head.center.y + Y);
}

I have already defined X and Y as integers and 'head' as a UIImage in my .h file. I get the error 'Property 'center' not found on object of type UIImage *' for the above line of code. Is there any way to change or cast this to UIImageView? I want to have UIImage because I am doing animations and drawing images on the view that I have defined. Quartzcore allows only UIImage and not UIImageView. So, what am I missing here?

3

There are 3 answers

1
Puran On

It's not found because it's not there!! Center, bounds, and frame is only for views. Any animation you want can be done with using UIImageView so whatever you are trying to do above is not the right way. So, I would suggest reading https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html

0
Eilon On

A UIImage doesn't have a center property because it's not a view. Use UIImageView and access it's image property to set it's image.

1
Rameswar Prasad On

UIImageView is derived from UIView so it has a center property while UIImage references to the image content so it doesn't have a center property. Instead of UIImage put UIImageView object there.