2016-08-31 5 views
1

다음 구독을 신속하게 처리하고 있습니다. 키보드를 언제 위로 움직이면되는지 알 필요가 있습니다. 컴파일되고 예상대로 작동하지만이 경고를 제거하는 방법을 알지 못합니다. 어떤 제안을 사전에NSNotifications에 가입 할 때 Objective C 선택기를 인수로 사용하는 방법은 무엇입니까?

// Subscribing class to recieve the notification 
func subscribeToKeyboardNotifications() { 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil) 
} 
// Shifting view's frame up 
func keyboardWillShow(notification: NSNotification) { 
    view.frame.origin.y -= getKeyboardHeight(notification) 
} 
// Getting keyboard height 
func getKeyboardHeight(notification: NSNotification) -> CGFloat { 
    let userInfo = notification.userInfo 
    let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue // of CGRect 
    return keyboardSize.CGRectValue().height 
} 

감사합니다 "목표 - C의 selector'keyboardWillShow '로 선언있는 방법!"

+0

하십시오이이 답을 확인 http://stackoverflow.com/questions/36366116/no-method-declared-with-objective-c-selector-for-notification-uikeyboardwillshow – Sandy

답변

1

사용 #selector :

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil) 
+0

귀하의 답변 주셔서 감사 하고이 질문은 이미 대답했다 :) 나는 구글이나 중복으로 질문을 만드는 동안 그것을 찾지 못했습니다. –