根据点击的文本字段移动UIView

根据点击的文本字段移动UIView,uiview,uikeyboard,Uiview,Uikeyboard,在我的一个视图上有两个文本字段,我正试图找出如何根据已点击的文本字段将视图移动到不同的位置 移动视图的功能在4英寸的设备上完全可以正常工作,因为视图控制器顶部和键盘之间有足够的空间容纳两个文本字段。但是,在3.5英寸的设备上,一次只能显示一个文本字段 以下是我目前拥有的代码: 视图将显示: NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboa

在我的一个视图上有两个文本字段,我正试图找出如何根据已点击的文本字段将视图移动到不同的位置

移动视图的功能在4英寸的设备上完全可以正常工作,因为视图控制器顶部和键盘之间有足够的空间容纳两个文本字段。但是,在3.5英寸的设备上,一次只能显示一个文本字段

以下是我目前拥有的代码:

视图将显示:

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
键盘将显示/键盘将隐藏:

    override func viewWillDisappear(animated: Bool) {
    NSNotificationCenter.defaultCenter().removeObserver(self)
}

func keyboardWillShow(notification: NSNotification) {
    var screenSize = UIScreen.mainScreen().bounds.size.height

    if screenSize == 480 {
        //
    } else {
        if keyboardActive == false {
            if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
                //let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
                var frame = self.budgetEntryView.frame
                frame.origin.y = frame.origin.y - 87 //keyboardSize.height + 167
                self.budgetEntryView.frame = frame
                keyboardActive = true
            }
        }
    }
}

如何确定已点击哪个文本字段并根据该字段移动视图?

为每个文本视图调用isFirstResponder方法,以确定已点击哪个文本字段。

工作正常。谢谢。