Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将文本字段移到键盘上方_Ios_Swift_Keyboard_Scrollview - Fatal编程技术网

Ios 将文本字段移到键盘上方

Ios 将文本字段移到键盘上方,ios,swift,keyboard,scrollview,Ios,Swift,Keyboard,Scrollview,我一直在实现文档中给出的代码,用于将UIView(如文本字段)推到键盘上方以使其可见-我理解并成功地实现了代码,但我只是对特定函数中的某些行感到困惑。谁能给我解释一下吗?我已经评论了我对编码的看法。如果我错了,请纠正我 func keyboardWasShown(notification: NSNotification) { //Need to calculate keyboard exact size due to Apple suggestions s

我一直在实现文档中给出的代码,用于将UIView(如文本字段)推到键盘上方以使其可见-我理解并成功地实现了代码,但我只是对特定函数中的某些行感到困惑。谁能给我解释一下吗?我已经评论了我对编码的看法。如果我错了,请纠正我

func keyboardWasShown(notification: NSNotification)
    {
        //Need to calculate keyboard exact size due to Apple suggestions
        self.scrollView.scrollEnabled = true//enable the scrol view
        let info : NSDictionary = notification.userInfo!//get the userinfo for height of the keyboard
        let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue().size//get the keyboard height
        let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize!.height, 0.0)

        self.scrollView.contentInset = contentInsets//adjusts the bottom content inset of the scroll view by the height of the keyboard , contentInset - The distance that the content view is inset from the enclosing scroll view.

        self.scrollView.scrollIndicatorInsets = contentInsets//scrollIndicatorInsets - The distance the scroll indicators are inset from the edge of the scroll view.

        var aRect : CGRect = self.view.frame
        aRect.size.height -= keyboardSize!.height
        if let activeFieldPresent = activeField//check for the textfield that is active
        {
            if (!CGRectContainsPoint(aRect, activeField!.frame.origin))
            {
                self.scrollView.scrollRectToVisible(activeField!.frame, animated: true)
            }
        }


    }
现在我的问题是这部分代码中发生了什么-

var aRect : CGRect = self.view.frame
            aRect.size.height -= keyboardSize!.height
            if let activeFieldPresent = activeField//check for the textfield that is active
            {
                if (!CGRectContainsPoint(aRect, activeField!.frame.origin))
                {
                    self.scrollView.scrollRectToVisible(activeField!.frame, animated: true)
                }
            }

请逐行解释一下。谢谢你的回答,我会很有帮助。

@Anbu.Karthik停止在标题中添加语言标签。请参阅@EricD。--有关您有价值的信息,我将继续关注this@Anbu.Karthik停止向标题添加语言标记。请参阅@EricD。--税务有关您的有价值信息,我将遵循以下步骤