0
我在我的一個視圖上有兩個文本字段,我想知道如何根據哪個文本字段已被挖掘將視圖移動到不同的位置。移動UIView基於哪個文本字段已被挖掘
移動視圖的功能在4英寸設備上工作得非常好,因爲兩個文本框都有足夠的空間放置在視圖控制器的頂部和鍵盤之間。但是,在3.5英寸設備上,一次只能顯示一個文本字段的空間。
這裏是我目前擁有的代碼:
viewWillAppear中:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
keyboardWillShow/keyboardWillHide:
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
}
}
}
}
我怎麼能弄清楚哪些文本字段已經被挖掘和移動基於這個觀點?
完美地工作。非常感謝。 – user3746428 2014-09-01 22:31:07