gpt4 book ai didi

ios - 在 iOS7 中向后滑动时使键盘与 UIView 同步动画

转载 作者:IT王子 更新时间:2023-10-29 07:56:14 24 4
gpt4 key购买 nike

我希望获得类似于 iOS7 中的消息应用程序(在大多数短信应用程序中也很常见)的行为,在对话 View 中,从屏幕左边缘向右滑动的行为类似于 UINavigationController 中的后退按钮。

我已经设法实现了这种行为,但是,如果键盘在呈现 View 中打开,当我开始向后滑动时,键盘会卡住并且不会随着我移动手指而向右显示动画。我想将键盘和呈现 View 作为一个单元进行动画处理,而不是好像键盘位于其他 View 之上并且它们在它后面进行动画处理,这就是我现在得到的(参见第二个屏幕截图):

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

通过简单地在 Xcode 5.0.2 中创建一个新的主从 iPhone 应用程序并在 StoryBoard 中的细节 View (最好在上半部分的某个地方)添加一个文本字段,运行该应用程序,可以很容易地重现该问题,添加一个项目,点击它进入详细 View 并单击您添加的文本字段。从设备左侧边缘滑动,同时将手指放在设备上,您会看到问题。

期望的行为:

Desired behavior

当前行为:

Keyboard tearing

最佳答案

不幸的是,没有内置方法可以做到这一点。我真的希望 UIViewController 会有类似 UIScrollViewKeyboardDismissModeInteractive 的东西。

现在,要在 viewController 之间做任何动画,你应该使用 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;

对于键盘你应该做这样的事情:

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

至于 keyboardSuperview - 你可以通过创建一个假的 inputAccessoryView 来获得它:

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

那么 super View 将是self.textField.inputAccessoryView.superview

关于ios - 在 iOS7 中向后滑动时使键盘与 UIView 同步动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20984224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com