我有一個視圖,如果在嘗試保存時未填充項條目的名稱字段,則彈出UIAlertView。我想顯示自己的自定義警報視圖。我用xib加載它:如何使用自定義視圖模擬UIAlertView模態行爲?
- (void)enterNameAlert {
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"AddNameAlertView" owner:self options:nil];
enterNameAlertView = [subviewArray objectAtIndex:0];
enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
enterNameAlertView.alpha = 0.0;
[self.view addSubview:enterNameAlertView];
[self.view bringSubviewToFront:enterNameAlertView];
//fade view in
[UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {
enterNameAlertView.alpha = 1.0;
} completion:NULL];
[UIView commitAnimations];
}
但是,您仍然可以在顯示警報時單擊視圖上的所有其他元素。理想情況下,我想製作alertview模式。作爲黑客,我只是在alertview啓動時將所有其他元素設置爲xxxx.enabled = NO,並在警報上按OK時切換回xxxx.enabled = YES。
必須有一個更好的方法來取消所有觸摸self.view,但不是self.enterNameAlertView。
如果我做self.view.userInteractionEnabled = NO它取消self.view所有觸及以及self.enterNameAlertView。
任何想法?
哇,這樣的小任務好像很多額外的繁重工作。推一個全新的viewcontroller只是爲了阻止用戶在alertview框架之外進行交互?有什麼像「觸及區域/邊界xyz =忽略」?另外,我還以爲你不能用透明背景推新視圖並看到它下面的視圖? – RyeMAC3
嘿關於推視圖控制器,我不是說,我說簡單的UIView。插入那不會是一個大問題。 – Suhaiyl
我已經試過了。我把1024×768的UIView主視圖和alertview之間,我仍然可以通過它觸及。哼,現在我想知道該視圖是否將userInteractionEnabled設置爲NO。這會有所作爲嗎?觸動它會通過嗎? – RyeMAC3