2014-09-15 5 views

답변

12

은 그냥 UIViewControllerUIKeyboardWillShowNotification 수신 :

// in your viewDidLoad: 

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification) 

// later in your class: 

func keyboardWillShow(notification: NSNotification) { 
    let frame = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() 
    // do stuff with the frame... 
} 
+2

스위프트 2.0에서 작동 viewDidLoad()

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil ) 

에 관찰자를 추가하려면 다음을 사용 뷰 컨트롤러가 해제되면 옵저버를 제거해야합니다. –

8

스위프트 2.0에서는 두 번째 방법은 여전히 ​​

관련 문제