iPhone键盘打开时如何调整视图位置?

发布于 2024-08-08 02:51:31 字数 96 浏览 11 评论 0 原文

在长度超过屏幕区域 50% 的表单中,输入将出现在键盘下方。 我想调整视图,以在键盘显示时保持所选输入始终可见,并在键盘消失时重置其位置。

有什么想法吗? 谢谢。

In forms that are longer than 50% of the screen area, inputs will appear underneath the keyboard.
I want to adjust the view to keep the selected input always visible when the keyboard shows and reset its position when the keyboard disappears.

Any ideas?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

揽月 2024-08-15 02:51:31

管理键盘讨论了如何接收键盘显示/取消显示的通知,以及如何保持内容可见(包括示例代码)。

The section Managing the Keyboard in the iPhone Application Programming Guide discusses how to receive notifications of keyboard display/undisplay, as well as how to keep your content visible (including sample code).

忆依然 2024-08-15 02:51:31

如果您使用的是 UIScrollView,则可以使用 -scrollRectToVisible:animated: 方法 移动到视图的特定部分。

如果您使用的是 UITableView,则可以使用 -scrollToRowAtIndexPath:atScrollPosition:animated: 方法 滚动到特定位置行,或 -scrollToNearestSelectedRowAtScrollPosition:animated:

If you're in a UIScrollView, you can use the -scrollRectToVisible:animated: method to move to a particular portion of the view.

If you're in a UITableView, you can use the -scrollToRowAtIndexPath:atScrollPosition:animated: method to scroll to a particular row, or - scrollToNearestSelectedRowAtScrollPosition:animated:.

も让我眼熟你 2024-08-15 02:51:31

尝试此代码:

#define kTextFieldMovementDistance      150.0 //You can set this according to your need
#define kMinimumMovementDuration        0.3f

- (void) slidingViewUpward: (BOOL) isSlidingUp
{
    CGFloat movementDistance = kTextFieldMovementDistance; 

    const float movementDuration = kMinimumMovementDuration;

    int movement = (isSlidingUp ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"animation" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);

    [UIView commitAnimations];
}

当您想要向上滑动视图时,或者当键盘成为第一响应者时,将 bool 值传递为 YES,否则传递 NO

Try This Code:

#define kTextFieldMovementDistance      150.0 //You can set this according to your need
#define kMinimumMovementDuration        0.3f

- (void) slidingViewUpward: (BOOL) isSlidingUp
{
    CGFloat movementDistance = kTextFieldMovementDistance; 

    const float movementDuration = kMinimumMovementDuration;

    int movement = (isSlidingUp ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"animation" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);

    [UIView commitAnimations];
}

When you want to slide the view in upwards Direction, or when the Keyboard became the first responder, the pass the bool value as YES otherwise NO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文