相关疑难解决方法(0)

UITextField文本跳转iOS 9

上一个问题的链接: UITextField文本跳转

简而言之:我有ViewController2个UITextField元素.当loginField是firstResponder之后

self.passwordField.becomeFirstResponder()
Run Code Online (Sandbox Code Playgroud)

登录字段中的文本跳转到左上角和后退.而且更奇怪的是:这个故障只是第一次再现,然后你需要重新创建ViewController才能观察到这种行为

这是故障的视频http://tinypic.com/player.php?v=6nsemw%3E&s=8#.VgVb3cuqpHx

我最终得到了这个(不适用于iOS 9):

func textFieldShouldReturn(textField: UITextField) -> Bool {
    if textField === self.loginField {
        self.loginField.resignFirstResponder()
        // Shitty workaround. Hi, Apple!
        self.loginField.setNeedsLayout()
        self.loginField.layoutIfNeeded()

        self.passwordField.becomeFirstResponder()
        return false
    }

    return true
}
Run Code Online (Sandbox Code Playgroud)

是否有人被这个错误所困扰?有什么建议?

键盘通知处理程序

我的主视图是UIScrollView,我将底部空间更改为superview,因此即使显示键盘,用户也可以滚动所有内容

func keyboardWillShow(notification : NSNotification) {
    let keyboardInfo = notification.userInfo!
    let keyboardFrame = keyboardInfo[UIKeyboardFrameEndUserInfoKey]!.CGRectValue
    let animDuration = keyboardInfo[UIKeyboardAnimationDurationUserInfoKey]!.doubleValue!

    UIView.animateWithDuration(animDuration, animations: {
        self.scrollViewBottom.constant = keyboardFrame.height
        self.view.layoutIfNeeded()

        let offsetY = CGRectGetMaxY(self.loginButton.frame) + 10 - self.scrollView.frame.height
        if offsetY > 0 …
Run Code Online (Sandbox Code Playgroud)

iphone ios swift ios9 swift2

12
推荐指数
3
解决办法
5361
查看次数

标签 统计

ios ×1

ios9 ×1

iphone ×1

swift ×1

swift2 ×1