Error: request for member 'location' in something not a structure or union
I am creating an app where when you touch a pimple it moves to a different location. This is the code that I put:
pimple.locati开发者_高级运维on = (320, 64);
(I have created an IBOutlet for pimple and connected it)
I get the following error:
request for member 'location' in something not a structure or union
Here is my .m code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:pimple];
if ( CGRectContainsPoint(pimple.bounds, point) ) {
[self checkcollision];
}
}
-(void)checkcollision {
label.text += 1;
pimple.hidden = YES;
pimple.location = (320, 64); //the error
sad.hidden = NO;
NSURL* popURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"pop" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((CFURLRef) popURL, &popID);
AudioServicesPlaySystemSound(popID);
}
Assuming that pimple
is a UIImageView
object (based on this SO question
), you would probably want to change its position by using the center
property.
pimple.center = CGPointMake(320, 64);
or
pimple.center = (CGPoint){320, 64};
The location property is (probably) of type CGPoint
(a struct), you can't just assign a point value by providing two numbers. You would typically assign it with the helper function CGPointMake
:
pimple.location = CGPointMake(320, 64);
or:
CGPoint location;
location.x = 320;
location.y = 64;
pimple.location = location;
精彩评论