笏我試圖是,每次用戶觸摸屏幕,我是在屏幕添加圖像在運行時陣列和清除它按鈕點擊
UIImage *img = [UIImage imageNamed:@"shoot_a.png"]; //bullet shot image
im.image = img;
[self.view addSubview:im];
增加一個小bulletr圖像時,如果用戶觸摸的50倍,屏幕上會顯示50張圖片。
現在我想,如果用戶點擊一個按鈕,所有這些子彈應該從屏幕上刪除。
我希望我明確我的問題。
[im removefromsuperview]
不適合我。
如果我想在運行時將圖像添加到數組,我該如何添加和釋放? 還是有沒有更好的方法來清除所有圖像 問候。
這是我的聯繫方式,即時通訊將在屏幕上FRM heere子彈圖片,,但這些圖像沒有在陣
// Touch method
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(restrictTap == YES){
NSUInteger numTaps = [[touches anyObject] tapCount];
NSString *numTapsMessage = [[NSString alloc] initWithFormat:@"%i", numTaps];
[numTapsMessage release];
// getting location
CGPoint touchLocation = [[touches anyObject] locationInView:self.view];
NSString *locationMessage = [[NSString alloc] initWithFormat:@"Location: X = %.0f Y = %.0f", touchLocation.x, touchLocation.y];
//bullet shot image
im = [[UIImageView alloc] initWithFrame:CGRectMake(self.location.x, self.location.y, 12.0, 12.0)];
float j =self.location.x;
float i =self.location.y;
img = [UIImage imageNamed:@"shoot_a.png"]; //bullet shot image
im.image = img;
//im.hidden = NO;
[self.view addSubview:im]; ///bullet shot image is over transparent view
[imageArray addObject:img];
}
}
@ this [imageArray addObject:im]; 我每次都得到0個對象.. wat做什麼? – iscavengers 2010-07-08 05:19:27
@shi:你是什麼意思?數組保持空白?現在有兩件事:你有'addObject:img'而不是'addObject:im',並且圖像視圖被過度保留。 – 2010-07-08 06:52:22
@georg yes array is emmmmpty,沒有圖像被添加到數組中。 它顯示0個對象 好吧,讓我試試img im的instread。 – iscavengers 2010-07-08 06:58:20