[英]How do I remove a UIImage View?
我正在使用的代碼會在視圖中加載標簽。 與其拖動起來,不如將其刪除,而是每次觸摸時都刪除以前的UIImageView並創建一個新的UIImageView。 這是我正在使用的代碼,但它只會不斷創建,並且不會在每一幀都刪除以前的圖像視圖。 僅供參考,我不想使用GL,Sprites或其他任何東西。 我要這個工作。
在viewDidLoad中:
float x = 160, y = 100, w =50, h=50;
image0 =[[UIImageView alloc] initWithFrame:CGRectMake(x,y,w,h)];
image0.image=[UIImage imageNamed:@"cow-35561_150.png"];
[self.view addSubview:image0];
開始接觸:
image0 = nil;
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
NSLog(@"%@", NSStringFromCGPoint(location));
image0 =[[UIImageView alloc] initWithFrame:CGRectMake(location.x,location.y,50,50)];
image0.image=[UIImage imageNamed:@"cow-35561_150.png"];
[self.view addSubview:image0];
要從層次結構中刪除視圖,請使用removeFromSuperview
[image0 removeFromSuperview];
image0 = nil;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.