[英]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.