2011-06-01 103 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