我想通過一次點擊就解除UIAlertView的任何位置。我想顯示一個沒有任何按鈕的UIAlertView。iOS如何在任何地方點擊一次UIAlertView?
我在這裏有標準的UIAlertView代碼,但我需要輸入如何解除它,如果可能的話。
使用UITouch?用UITapGestureRecognizer?
謝謝。
編輯:
在viewDidLoad中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];
}
我需要這個空的視圖正在警報時顯示警報,然後我可以關閉一個水龍頭警報。
我想:
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響應函數。空視圖有什麼問題?
第二個編輯:
我想在這種情況下,實現在Kindle應用程序中選擇一個詞,類似的功能後,以顯示與解釋一個小觀點,如果你有一個。 也許我應該創建一個UIView而不是UIAlertView?但Kindle應用程序中的小視圖對於低於它的陰影非常好,它怎麼可能?
嗯,我的目標不是製作或使用由複雜而長的代碼組成的視圖。這個iToast真的很棒,但我想知道是否有可能使用更少的代碼來製作這樣的功能?感謝您與我們分享這個鏈接。 – wagashi
這是無法幫助的!我添加了.m:' - (void)setFrame:(CGRect)rect {0} {0}};}} [超級setFrame:CGRectMake(0,0,rect.size.width,300)]; \t \t [super setFrame:CGRectMake(0,0,100,100)]; \t \t //下面的代碼使UIAlertView居中。 \t //self.center = CGPointMake(320/2,480/2); \t \t //我的自定義cgpointmake \t self.center = CGPointMake(200,400); }' – wagashi
是的,你確實回答了我的問題。然而,我不會在我的「警戒」中提供很多信息,所以CGRectMake 0,0,100,100對我而言就非常完美。我想知道是否可以在UIAlertView中更改文本的字體大小? – wagashi