【问题标题】:Xcode 5 and iOS 8 keyboard scroll not workingXcode 5 和 iOS 8 键盘滚动不起作用
【发布时间】:2015-03-13 22:17:00
【问题描述】:

直截了当,当我使用 Xcode 6 构建项目时,当键盘即将显示时,屏幕上的组件会正确向上滚动。

但是,当我使用 Xcode 5 构建时,所有组件都会离开屏幕(也就是它们移动得太高了)。我搜索了,但我找不到问题。

此问题仅在 iOS 8 横向模式下出现。在 iOS 7 上一切正常。有谁知道问题是什么?由于某些原因,必须使用 Xcode 5 进行构建。 谢谢!

视图创建时间

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShown:) name:UIKeyboardWillShowNotification object:nil];

事件处理程序

- (void)keyboardShown:(NSNotification *)notification{
    CGSize kbSize = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    float kbHeight = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? kbSize.height : kbSize.width;
    if( [[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) kbHeight = kbSize.height;

    _origScrollIndicatorInsets = _legsTableView.scrollIndicatorInsets;
    _origContentInset = _legsTableView.contentInset;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbHeight, 0.0);
    _legsTableView.contentInset = contentInsets;
    _legsTableView.scrollIndicatorInsets = contentInsets;

    if (_activeTextField) {
        CGRect fieldRect = [_legsTableView convertRect:_activeTextField.bounds fromView:_activeTextField];
        [_legsTableView scrollRectToVisible:fieldRect animated:YES];
    }
}

【问题讨论】:

    标签: xcode ios7 scroll ios8 keyboard


    【解决方案1】:

    在 Xcode 6 中创建和使用的项目并不总是与 Xcode 5 兼容。有些事情会发生变化,例如故事板和 Xcode 6 的自动布局。我认为没有任何理由需要在 Xcode 5 中构建它,我假设您正在寻找向后兼容性。然后,您可以更改该应用程序的部署目标。如果您将其更改为 7 或较旧的 iOS,您将看到它在较旧的 iOS 上如何工作,但仍使用最新版本构建。

    【讨论】:

    • 嗨!感谢您的评论。我使用 Xcode 5 为客户构建还有其他一些原因。但我猜你是对的。我没有在我的项目中使用故事板。部署目标设置为需要的 iOS 6.1。
    • 我认为这与情节提要有关,如果不使用它们我不确定。我建议在 Xcode 5 中为这些应用程序开发并在 Xcode 6 中打开之前复制文件。这将确保您始终可以恢复到 Xcode 5 版本。通常 Xcode 可以轻松处理旧版本,但必须进行修改才能处理新版本。
    【解决方案2】:

    从这篇文章中,我找到了计算高度的答案,而且效果很好。 keyboard height varies in ios8

    - (void)keyboardWillShow:(NSNotification*)note {
          NSDictionary* info = [note userInfo];
          CGSize _kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
          float kbHeight = _kbSize.width > _kbSize.height ? _kbSize.height : _kbSize.width;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-12
      • 2014-09-06
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 2021-02-01
      • 2015-01-13
      相关资源
      最近更新 更多