2010-07-14 4 views
1

Collison mais son seul travail pour 1 'imagecomment faire une collision générale avec des images en boucle

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint p = [touch locationInView:self.view]; 
    if (CGRectContainsPoint(CGRectMake(myImage1.frame.origin.x, myImage1.frame.origin.y, myImage1.frame.size.width, myImage1.frame.size.height), p)) 
    { 
     [pieMenu showInView:self.view atPoint:p]; 
    } 
} 

cela fonctionnera soit pour

[self addImageSubViewAtX:160.0 atY:190.0]; 

OU

[self addImageSubViewAtX:90.0 atY:140.0]; 

mais pas ensemble

cette méthode est défini par vous

- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y { 
    CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
    myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 
    [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
    [self.view addSubview:myImage1];   
} 
+0

Je pense que vous avez besoin de cette si pour les deux images, non? alors, mettez une autre si peut résoudre si (CGRectContainsPoint (CGRectMake (myImage1.frame.origin.x, myImage1.frame.origin.y, myImage1.frame.size.width, myImage1.frame.size .height), p)) – vodkhang

+0

je l'ai fait mais ne fonctionne pas :(aucune idée – ram

Répondre

0

Je suggère de faire une méthode recevoir un paramètre, car ils ne sont pas tout à fait la même

- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y { 
    CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
    myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 
    [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
    [self.view addSubview:myImage1]; 

} 

puis vous l'appelez 2 fois: [self addImageSubViewAtX:160.0 atY:190.0] and [self addImageSubViewAtX:90.0 atY:140.0]

+0

merci mais où dois-je appeler \t [auto addImageSubViewAtX: 160,0 Aty: 190,0]; \t [self addImageSubViewAtX: 90.0 atY: 140.0]; je les veux dans viewDidLoad() – ram

+0

Oui, vous pouvez les appeler à viewDidLoad() – vodkhang

+0

maintenant une question parfaite est là je fais cela pour Collison mais son seul travail pour 1 'image - (void) touchesBegan: (NSSet *) touche withEvent: (UIEvent *) {événement \t UITouch * touche = [touche anyObject]; \t CGPoint p = [touch locationInView: self.view]; \t \t \t \t \t \t \t \t \t si (CGRectContainsPoint (CGRectMake (myImage1.frame.origin.x, myImage1.frame.origin.y, myImage1.frame.size.width, myImage1. frame.size.height), p)) { \t \t \t \t [pieMenu showInView: self.view atPoint: p]; \t} \t } – ram

Questions connexes