当我尝试在键盘出现时调整textView和按钮的位置时出现问题。
我试过了:
override func viewDidLoad() {
super.viewDidLoad()
//...Code here .. //
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardDidShow:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardDidHide:", name:UIKeyboardDidHideNotification, object: nil)
}
func keyboardDidShow(notification :NSNotification){
//println("A aparut")
print("\(self.messageText.frame.origin)")
var c = notification.userInfo
var keyboardInfo = notification.userInfo as NSDictionary
var keyboardFrameBegin = keyboardInfo.valueForKey(UIKeyboardFrameBeginUserInfoKey).size as CGSize
// UIView.beginAnimations(nil, context: nil)
//UIView.setAnimationDuration(0.25);
//print(" is the height \(self.messageText.frame.height)")
UIView.animateWithDuration(0 , animations: {
self.ChatView.frame = CGRectMake(self.ChatView.frame.origin.x, self.ChatView.frame.origin.y , self.ChatView.frame.width, 150 )
self.sendButton.frame = CGRectMake(self.sendButton.frame.origin.x, self.sendButton.frame.origin.y + keyboardFrameBegin.height, self.sendButton.frame.width , self.sendButton.frame.height)
self.messageText.frame = CGRectMake(self.messageText.frame.origin.x,self.messageText.frame.origin.y + keyboardFrameBegin.height ,self.messageText.frame.width,self.messageText.frame.height);
})
//UIView.commitAnimations()
}
当我尝试获取密钥的值时,我得到一个nil错误。
我该怎样用?
替换这一行?当我尝试对此问题进行硬编码时,我注意到的另一件事[当每个元素出现时为每个元素添加200并且当它消失时减去200]是方法被多次调用。
我的意思是框架越来越远,直到它到达月球。
是模拟器还是什么?