xcode 删除添加的子视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14478220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:35:52  来源:igfitidea点击:

Remove added SubView

xcode

提问by Loralon

i'm tring to remove an added subview but i can't do it... i add the subView in a UIButton

我想删除添加的子视图,但我不能这样做......我在 UIButton 中添加子视图

//Create the first status image and the indicator view
UIImage *statusImage = [UIImage imageNamed:@"loader_01.png"];
UIImageView *activityImageView = [[UIImageView alloc]
                                  initWithImage:statusImage];


//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"loader_01.png"],
                                     [UIImage imageNamed:@"loader_02.png"],
                                     [UIImage imageNamed:@"loader_03.png"],
                                     [UIImage imageNamed:@"loader_04.png"],

                                     nil];


//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 0.3;


//Position the activity image view somewhere in
//the middle of your current view
activityImageView.frame = CGRectMake(
                                     self.view.frame.size.width/2
                                     -statusImage.size.width/2, 
                                     self.view.frame.size.height/2
                                     -statusImage.size.height/2, 
                                     statusImage.size.width, 
                                     statusImage.size.height);

//Start the animation
[activityImageView startAnimating];


//Add your custom activity indicator to your current view
[self.view addSubview:activityImageView];

Now i'd like to remove activityimageView with another IBAction...but Xcode doesn't know that SubView... Any Idea?!

现在我想用另一个 IBAction 删除 activityimageView ......但 Xcode 不知道那个 SubView ......有任何想法吗?!

回答by Pratyusha Terli

place your

放置你的

UIImageView *activityImageView 

in .h file and in IBAction write code like this

在 .h 文件和 IBAction 中编写这样的代码

[activityImageView removeFromSuperView];