반응형
Swift version : 1.2
iOS version : 8.4
Swift 문법도 익숙치 않은데 NSNotificationCenter 사용하려는데 막히는 부분이 많고...
Notificaiton 에서 keyboard 관련 정보 가져오려는데.... 왜이리 오류가 많은지..
다음과 코드가 동작함을 확인하였으니 참고하세요.
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
func keyboardWillShow(notification: NSNotification) { let userInfo = notification.userInfo! let beginFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue() let endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue let animationOptions = UIViewAnimationOptions((userInfo[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).unsignedLongValue << 16) UIView.animateWithDuration(duration, delay: 0.0, options: animationOptions, animations: { () -> Void in }, completion: nil) }
Swift version : 2.0
iOS version : 9.0
animationOptions 를 구하는 방법이 변경되었습니다.
func keyboardWillShow(notification: NSNotification) { let userInfo = notification.userInfo! let beginFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue() let endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue let animationOptions = UIViewAnimationOptions(rawValue: (userInfo[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).unsignedLongValue) UIView.animateWithDuration(duration, delay: 0.0, options: animationOptions, animations: { () -> Void in }, completion: nil) }
반응형
'Programming > iOS' 카테고리의 다른 글
ERROR ITMS-90206 "Invalid Bundle. The bundle at 'name.app/PlugIns/Extension.appex' contains disallowed file 'Frameworks'." (0) | 2015.10.06 |
---|---|
Error loading the plugin with path `/Library/Ruby/Gems/2.0.0/gems/cocoapods-stats-0.6.0/lib/cocoapods_plugin.rb`. (0) | 2015.08.28 |
ReactiveCocoa 한번 써보자 (0) | 2015.07.16 |
Could not load NIB in bundle (0) | 2015.06.23 |
앱 실행 중 언어 설정 변경 (0) | 2015.02.11 |