ワンタップでUIAlertViewを閉じたいです。ボタンなしでUIAlertViewを表示したい。
ここに標準のUIAlertViewコードがありますが、可能であれば、それを閉じる方法を入力する必要があります。
UITouchで?UITapGestureRecognizerを使用しますか?
ありがとうございました。
編集:
viewDidLoadで
ここで「alert」という名前のalertviewの初期化
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];
}
アラートが表示されたときにこのemptyviewがアラートになっている必要があります。その後、ワンタップでアラートを閉じることができます。
私は試した:
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];
}
もちろん、アラートはhandleSingleTap関数に応答しました。emptyviewの何が間違っていましたか?
2番目の編集:
この場合、私が達成したいのは、単語を選択した後、説明付きの小さなビューを表示することです。Kindleアプリにある場合は、同様の機能です。たぶん、UIAlertViewの代わりにUIViewを作成する必要がありますか?しかし、Kindleアプリの小さなビューは、その下に影が付いているのでとても素敵です、どうしてそれは可能ですか?