mon*_*ker 53
UIKeyboardAnimationDurationUserInfoKey
是保存动画持续时间的字典键的const字符串标识符,因此无法轻松更改它.
使键盘在没有动画的情况下显示的一种方法是观察键盘通知并在即将出现时禁用动画,然后重新启用它们.当然,这也会禁用任何其他动画.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willShowKeyboard:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didShowKeyboard:)
name:UIKeyboardDidShowNotification
object:nil];
- (void)willShowKeyboard:(NSNotification *)notification {
[UIView setAnimationsEnabled:NO];
}
- (void)didShowKeyboard:(NSNotification *)notification {
[UIView setAnimationsEnabled:YES];
}
Run Code Online (Sandbox Code Playgroud)
然后是相同的UIKeyboardWillHideNotification/UIKeyboardDidHideNotification
通知.
添加适当的委托方法:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView setAnimationsEnabled:NO];
}
Run Code Online (Sandbox Code Playgroud)
要么
- (void)textViewDidBeginEditing:(UITextView *)textView {
[UIView setAnimationsEnabled:NO];
}
Run Code Online (Sandbox Code Playgroud)
添加键盘通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didShowKeyboard:) name:UIKeyboardDidShowNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
方法:
- (void)didShowKeyboard:(NSNotification *)notification {
[UIView setAnimationsEnabled:YES];
}
Run Code Online (Sandbox Code Playgroud)
尝试
[UIView performWithoutAnimation:^{
[textField becomeFirstResponder];
}];
Run Code Online (Sandbox Code Playgroud)
我发现最好的解决方案是使用UIView.setAnimationsEnabled(_ enabled: Bool)
.
斯威夫特3
UIView.setAnimationsEnabled(false)
textField.becomeFirstResponder()
// or textField.resignFirstResponder() if you want to dismiss the keyboard
UIView.setAnimationsEnabled(true)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16581 次 |
最近记录: |