【发布时间】:2012-01-05 19:54:34
【问题描述】:
我想一键关闭 UIAlertView。我想显示一个没有任何按钮的 UIAlertView。
我在这里有标准的 UIAlertView 代码,但如果可能的话,我需要输入如何关闭它。
使用 UITouch?使用 UITapGestureRecognizer?
谢谢。
编辑:
在 viewDidLoad 中
alertview 在此处初始化,名称为“alert”
if (alert)
{
emptyview = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
emptyview.backgroundColor = [UIColor clearColor];
[self.view addSubview:emptyview];
[emptyview addSubview:alert];
NSLog (@"emptyview is there!");
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[emptyview addGestureRecognizer:singleTap];
[singleTap release];
}
但是这个emptyview根本没有响应,也没有响应handleSingleTap选择器,我重写了一下:
-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
[alert dismissWithClickedButtonIndex:0 animated:YES];
[emptyview removeFromSuperview];
}
我需要这个空视图在显示警报时处于警报状态,然后我可以一键关闭警报。
我试过了:
if (alert)
{
emptyview = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
emptyview.backgroundColor = [UIColor clearColor];
[self.view addSubview:emptyview];
[emptyview addSubview:alert];
NSLog (@"emptyview is there!");
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[alert addGestureRecognizer:singleTap];
[singleTap release];
}
当然,alert 确实响应了 handleSingleTap 函数。我对 emptyview 做错了什么?
第二次编辑:
在这种情况下,我想要实现的是在选择一个单词后显示一个带有解释的小视图,类似 Kindle 应用程序中的功能,如果你有的话。 也许我应该创建一个 UIView 而不是 UIAlertView?但是kindle app里的小view这么好看,下面有阴影,怎么可能?
【问题讨论】:
标签: ios uialertview uitouch uitapgesturerecognizer