我有3个文本字段。我根据文本字段但的位置为视图创建了一个动态动画,当我检查“连接硬件键盘”时,视图使动画区域变黑。
有人能帮帮我吗?
答案 0 :(得分:0)
您可以注册4个通知。这是一个例子:
#pragma mark - Lifecycle
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDisappear:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidAppear:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidDisappear:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Notifications
- (void)keyboardWillAppear:(NSNotification *)note
{
}
// E.t.c
这些通知的好处是,只有在切换虚拟键盘时才会触发它们。因此,您可以使用这些通知触发视图切换。当用户连接硬件键盘时,不会发生任何事情。