我在當前的UIViewController
中添加了UIView
。當觸摸屏幕上的任何地方時,我需要刪除UIView
。我在UIView
中有UIButton
。但是,如果我點擊UIButton
,那麼也刪除UIView
。在touchevent上刪除UIView
其實我在UIView
中添加了一個按鈕(退出),點擊時應該關閉currentview
並去homeViewController
。但是,如果我點擊當前視圖上的任何地方,而不是UIView
上的按鈕,則應刪除UIView
。但在我的情況下,如果我點擊按鈕然後UIView
被刪除。
logout= [[UIView alloc]initWithFrame:CGRectMake(210,lbllogin.frame.origin.y+lbllogin.frame.size.height, 80, 50)];
logout.backgroundColor = [UIColor yellowColor];
btnSignout = [UIButton buttonWithType:UIButtonTypeCustom];
[btnSignout addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
btnSignout = CGRectMake(0,0,80,13);
[logout addSubview: btnSignout];
[self.view addSubview:logout];
UIButton *btnsignout=[[UILabel alloc]init];
[lblsignout setFrame:CGRectMake(0, 0, 80, 13)];
lblsignout.textAlignment = NSTextAlignmentLeft;
lblsignout.backgroundColor = [UIColor clearColor];
lblsignout .font=[UIFont fontWithName:@"Helvetica-Bold" size:14];
[email protected]"Sign out";
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[logout removeFromSuperview];
}
是u能告訴我怎麼樣? –