向后滑动 iOS 7 时,保持 UIKeyboard 在视图中



我有一个视图控制器,可以用新的交互式PopGestureRecognizer弹出。如果存在键盘并且轻扫动画开始,则键盘不会随视图移动。我看过这个问题,并在我的视图控制器中像这样实现它,但被驳回了

-(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不正确。

仔细检查它是否nil。如果是,您忘记添加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];
}

刚刚为iOS8找到了非常简单的解决方案

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.aTextInputView resignFirstResponder];
}

相关内容

  • 没有找到相关文章

最新更新