![](/img/trans.png)
[英]Removing View from its SuperView, Notifying the Subviews on iPhone
[英]Subviews are not removing while removing the superview in iPad
我创建了一个UIView。一个搜索栏被添加为视图的子视图。搜索栏也是通过代码创建的。
我给视图赋予了UIAnimation以获得像视图一样的下拉菜单。
到目前为止,它工作正常。
问题是,当我删除超级视图时,视图已经走了,但搜索栏仍然存在。
以下是一些代码:
@interface ATViewController : UIViewController<UISearchBarDelegate>
{
UIView *dropView;
UISearchBar *searchBar;
}
- (void)viewDidLoad
{
dropView = [[UIView alloc]initWithFrame:CGRectMake(70, 70, 150, 100)];
searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,150,0)];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(IBAction)buttonClicked:(id)sender{
// self.searchBar.delegate = self;
[dropView addSubview:searchBar];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.9];
dropView.backgroundColor = [UIColor blueColor];
dropView.frame = CGRectMake(70, 70, 150, 550);
self.searchBar.frame=CGRectMake(0,0, 150, 40);
[UIView commitAnimations];
[self.view addSubview:dropView];
}
-(void)doSingleTap:(UITapGestureRecognizer *)sender
{
switch (sender.numberOfTapsRequired) {
case 1:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
dropView.frame = CGRectMake(70, 70, 150, 0);
self.searchBar.frame=CGRectMake(0, 0, 150, 0);
[UIView commitAnimations];
break;
default:
break;
}
}
添加子视图
删除subView之后
您没有在代码中删除超级视图。 您只是将其高度减小到零。 如果你想在searchBar
要与一起修剪dropView
然后设置dropView
的clipToBounds为YES。 即;
dropView.clipToBounds = YES:
在将其高度减小到零之前。
注意,您还将搜索栏的高度也降低到了零。 但是我认为您不允许编辑UISearchBar的高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.