iOS中有NSNotificationCenter可以接收Notify
其中鍵盤彈出事件是滿常用到的,例如要控制UIScrollView的範圍和大小
以鍵盤事件的範例如下:
可以在viewWillAppear中註冊Notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
但記得要在viewWillDisappear中移除
[[NSNotificationCenter defaultCenter] removeObserver:self];
如果鍵盤有彈出或是相關的事件,就會進入以下method:
-(void)keyboardDidShow:(NSNotification*)notif{ NSLog(@"keyboard show"); } -(void)keyboardDidHide:(NSNotification *)notif{ NSLog(@"keyboard hide"); }
同步發表於 MyAndroid
沒有留言:
張貼留言