iPhone應用中,添加subView到窗口,還要實現一個功能,在點擊關閉按鈕是,應該subView隱藏起來,這是創建subView的代碼:
UIView*subView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 1024,768)];
subView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgPopupback.png"]];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:subView];
關閉按鈕:
-(void)closeButtonAction{
NSLog(@"CLicked on this button");
[subView removeFromSuperview] ;
self.tableView.userInteractionEnabled=TRUE;
}
使用removefromsuperview
刪除subView,如果只是想隱藏 subView.hidden = YES;,
在按鈕動作內執行。