我有一个视图控制器,可以使用新的interactivePopGestureRecognizer弹出.如果存在键盘并且滑动动画开始,则键盘不随视图移动.我已经看过这个
question,并在我的视图控制器中实现了这个被解雇的
-(void)viewWilldisappear:(BOOL)animated
{
[super viewWilldisappear:animated];
[self.transitionCoordinator animatealongsideTransitionInView:self.aTextInputView.keyboardSuperView animation:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGRect frame = self.aTextInputView.keyboardSuperView.frame;
frame.origin.x = self.view.frame.size.width;
self.aTextInputView.keyboardSuperView.frame = frame;
} completion:nil];
}
现在,当视图动画消失时,我得到的是键盘从屏幕动画到320点的x点,这就像我设置的那样有意义,我的问题是如何通过向后滑动让键盘动画?
更新
对于任何在视图消失时看到奇怪动画的人,您可以通过执行此操作来移除键盘.
[self.transitionCoordinator notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context){
if (![context isCancelled]) {
[keyboardSuperview removeFromSuperview];
}
}];
解决方法
你的代码片段中有很多自定义代码,如果我错了,请纠正我,但似乎你的self.aTextInputView.keyboardSuperView不正确.
仔细检查它是不是零.如果是,则忘记添加inputAccessoryView.
以下是没有任何扩展名的完整代码段:
- (void)viewWilldisappear:(BOOL)animated
{
[super viewWilldisappear:animated];
UIView *keyboardSuperview = self.textField.inputAccessoryView.superview;
[self.transitionCoordinator animatealongsideTransitionInView:keyboardSuperview
animation:
^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGRect keyboardFrame = keyboardSuperview.frame;
keyboardFrame.origin.x = self.view.bounds.size.width;
keyboardSuperview.frame = keyboardFrame;
}
completion:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.textField.inputAccessoryView = [[UIView alloc] init];
}