Objective c 错误:请求成员';地点';在非结构或联盟中
我正在创建一个应用程序,当你触摸一个丘疹时,它会移动到另一个位置。这是我写的代码:Objective c 错误:请求成员';地点';在非结构或联盟中,objective-c,xcode,Objective C,Xcode,我正在创建一个应用程序,当你触摸一个丘疹时,它会移动到另一个位置。这是我写的代码: pimple.location = (320, 64); (我为粉刺创建了一个IBOutlet并将其连接起来) 我得到以下错误: 在非结构或联合中请求成员“位置” 这是我的.m代码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [touches anyObject];
pimple.location = (320, 64);
(我为粉刺创建了一个IBOutlet并将其连接起来)
我得到以下错误:
在非结构或联合中请求成员“位置”
这是我的.m代码:
-(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);
}
location属性(可能)的类型为CGPoint
(一个结构),您不能只通过提供两个数字来指定一个点值。您通常会使用helper函数CGPointMake
来分配它:
pimple.location = CGPointMake(320, 64);
或:
假设
pimple
是UIImageView
对象(基于),您可能希望使用center
属性更改其位置
pimple.center = CGPointMake(320, 64);
或
什么是位置?它是什么类型的数据类型?
pimple.center = CGPointMake(320, 64);
pimple.center = (CGPoint){320, 64};