2011-06-01 224 views

回答

1

您可以提供一個取消/隱藏按鈕(在鍵盤之外)或隱藏在鍵盤之外的任何地方。這兩個是常見的做法。

0

試試這個。它可能會幫助您在觸摸屏幕時隱藏鍵盤 。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 

} 
2

經過一段時間的研究,我發現沒有真正滿意的答案。一些解決方案破解了「完成」按鈕,但這對於本地化應用程序來說效果不佳。我的應用程序不使用任何單詞,所以我絕對不想要「完成」按鈕。

正如taskinoor所提到的,如果視圖在其他地方被觸摸,編輯就很方便。這就是我所做的,和這裏的代碼顯示的細節:編程創建文本框

aTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; 
[aTextField addTarget:self action:@selector(c1Update) forControlEvents:UIControlEventEditingDidEnd]; 
aTextField.keyboardType = UIKeyboardTypeNumberPad; 
[yourView addSubview:aTextField]; 
c1Value = aTextField; // I like to keep a pointer for UI updates, alpha etc. 

在c1Update會發生什麼:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self updateViewColors]; 

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped)]; 
    tapRecognizer.numberOfTapsRequired = 1; 
    [self.view addGestureRecognizer:tapRecognizer]; 
} 

- (void) viewTapped { 
    if (c1Value.isFirstResponder) {[c1Value resignFirstResponder];} // dismisses keyboard, which causes c1Update to invoke. 
} 
:上圖

- (void)c1Update { 
    [[self brain] setC1:[c1Value.text intValue]]; // update the model 
} 

手勢識別

+0

防止在視圖中其他位置的按鈕上觸摸 – 2011-12-30 23:52:30