刷回iOS 7时保留UIKeyboard的视图

我有一个可以用新的interactivePopGestureRecognizer弹出的视图控制器。 如果存在键盘并且滑动动画开始,则键盘不随视图移动。 我已经看过这个问题,并在我的视图控制器中像这样执行它,并被解散

-(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];
}
链接地址: http://www.djcxy.com/p/77573.html

上一篇: Keep UIKeyboard with view when swiping back iOS 7

下一篇: conditional properties in angularJS Application between two controllers