如何显示全屏模式视图,然后如果用户触摸视图上的任何位置,视图将自行删除。
答案 0 :(得分:0)
您可以提供一个自定义按钮作为背景的模态视图,然后当您按下按钮或“背景”时,可以调用[self dismissModalViewControllerAnimated:YES];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view] == self) {
if ([touch tapCount] == 2) {
/* 2 touches here, you can dismiss your view */
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view] == self) {
if ([touch tapCount] == 1) {
/* 1 touch, dismiss your view */
}
}
答案 1 :(得分:0)
如果您在UIViewController的子类中执行此操作,则可以执行此类操作。这将触发最初加载视图时出现的模态,并在点击屏幕时触发模态消失。
-(void) viewDidLoad{
UIViewController *modalViewController = [[UIViewController alloc] init];
[modalViewController addTarget:self action:@selector(_dismissModal) forControlEvents:UIControlEventTouchUpInside];
[self presentModalViewController:modalViewController animated:YES];
}
-(void)_dismissModal{
[self dismissModalViewControllerAnimated:YES];
}
答案 2 :(得分:0)