Swift 文本编辑时将文本框上移

前端之家收集整理的这篇文章主要介绍了Swift 文本编辑时将文本框上移前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        
        NSLog("将要开始编码")
        var offset : CGFloat = CGFloat(self.view.frame.size.height) - CGFloat(self.txt_phone.frame.origin.y) - CGFloat(self.txt_phone.frame.size.height) - 216 - 50
        if(offset <= 0)
        {
            UIView.animateWithDuration(0.3,animations: {
                var frame : CGRect = self.view.frame
                frame.origin.y = offset
                self.view.frame = frame
            })
        }
        return true
    }
    func textFieldDidEndEditing(textField: UITextField) {
        
        UIView.animateWithDuration(0.3,animations: {
            var frame : CGRect = self.view.frame
            frame.origin.y = 0
            self.view.frame = frame
        })
    }

猜你在找的Swift相关文章