1
我創建了UIView.A視圖添加爲子視圖。搜索欄也是通過代碼創建的。子視圖不會移除,同時移除iPad中的超級視圖
我給了視圖的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;
}
}
添加子視圖
移除子視圖
後
謝謝老兄。它的工作 – suji 2013-03-06 18:25:05