2011-05-28 102 views
-2

我正在創建一個應用程序,當你觸摸一個疙瘩時,它移動到不同的位置。這是我把代碼:錯誤:請求成員'位置'的東西不是結構或工會

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); 
} 
+1

是什麼位置?它是什麼類型的數據類型? – 2011-05-28 15:30:26

回答

1

位置屬性(可能是)類型CGPoint(一個結構體),您不能只通過提供兩個數字來指定點值。

pimple.location = CGPointMake(320, 64); 

或:

CGPoint location; 
location.x = 320; 
location.y = 64; 
pimple.location = location; 
2

假設pimpleUIImageView對象(基於this SO question),你可能會想用改變立場,你通常會用輔助功能CGPointMake它分配center屬性。

pimple.center = CGPointMake(320, 64); 

pimple.center = (CGPoint){320, 64};