在iOS7中向后滑动边缘时,使键盘与UIView同步动画 [英] Animate the keyboard in sync with the UIView while edge-swiping back in iOS7

查看:134
本文介绍了在iOS7中向后滑动边缘时,使键盘与UIView同步动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS7中获得类似于Messages app(在大多数短信应用程序中也很常见)的行为,在对话视图中,从屏幕左边缘向右滑动就像UINavigationController中的后退按钮一样。

I'd like to get the behavior similar to Messages app (also common in most texting apps) in iOS7, where in a conversation view swiping right from the left edge of the screen would behave like the back button in a UINavigationController.

我已设法实现此行为,但是,如果键盘在演示视图中打开,当我开始向后滑动时,键盘卡住并且没有动画我移动手指时向右看。我想将键盘和呈现视图设置为一个单元,而不是将键盘放在其他视图的顶部,并且它们在它后面动画,这就是我现在所获得的(请参阅第二个屏幕截图):

I have managed to implement this behavior, however, if the keyboard is open in the presenting view, when I start swiping back, the keyboard gets stuck and does not animate with the view to the right as I move my finger. I'd like to animate keyboard and the presenting view as one unit, not as if keyboard is on top of the other views and they are animating behind it, which is what I get now (see the second screenshot):

更新:请注意,主视图动画完成后键盘最终会消失;我关注的是键盘的位置滑动过程中,当你持续触摸设备的一半时,这与实际视图不同步。第二个屏幕截图阐明了这种期望的行为。我也想知道为什么它不是默认的。)

(UPDATE: Note that the keyboard will eventually go away after the main view animation is finished; what I am focused on is the position of keyboard during the swipe process, and when you keep touching the device half of the way, which is not in sync with the actual view. The second screenshot clarifies this desired behavior. I also wonder why it is not the default.)

只需在Xcode 5.0.2中创建一个新的主 - 细节iPhone应用程序并在详细信息视图中添加文本字段(最好在某处),就可以轻松复制该问题StoryBoard中的上半部分,运行应用程序,添加项目,点击它以转到详细视图并单击您添加的文本字段。边缘从设备左侧滑动,同时将手指放在上面,您将看到问题。

It is easy to replicate the issue by simply creating a new master-detail iPhone app in Xcode 5.0.2 and adding a Text Field to the detail view (preferably somewhere in the upper half) in the StoryBoard, running the app, adding an item, tapping on it to go to the detail view and clicking on the text field you added. Edge-swipe from the left side of the device while keeping your finger on it and you'll see the issue.

所需行为:

目前的行为:

推荐答案

不幸的是,没有内置方法可以做到这一点。我真的希望 UIScrollViewKeyboardDismissModeInteractive 对于 UIViewController s。

Unfortunately, there is no built-in method to do that. I really hope there will be something like UIScrollViewKeyboardDismissModeInteractive for UIViewControllers.

目前,要在viewControllers之间执行任何动画,您应该使用 transitionCoordinator

For now, to do any animations in-between viewControllers, you should use a transitionCoordinator:

- (BOOL)animateAlongsideTransition:(void (^)(id <UIViewControllerTransitionCoordinatorContext>context))animation
                        completion:(void (^)(id <UIViewControllerTransitionCoordinatorContext>context))completion;

- (BOOL)animateAlongsideTransitionInView:(UIView *)view
                               animation:(void (^)(id <UIViewControllerTransitionCoordinatorContext>context))animation
                              completion:(void (^)(id <UIViewControllerTransitionCoordinatorContext>context))completion;

对于键盘你应该这样做:

For the keyboard you should do something like this:

[self.transitionCoordinator animateAlongsideTransitionInView:self.keyboardSuperview
                                                   animation:
^(id<UIViewControllerTransitionCoordinatorContext> context) {
    self.keyboardSuperview.x = self.view.width;
}
                                                  completion:nil];

至于 keyboardSuperview - 你可以得到通过创建一个假的 inputAccessoryView

As for keyboardSuperview - you can get that by creating a fake inputAccessoryView:

self.textField.inputAccessoryView = [[UIView alloc] init];

然后超级视图将是 self.textField.inputAccessoryView.superview

这篇关于在iOS7中向后滑动边缘时,使键盘与UIView同步动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆