鍵盤事件 - 使用NSNotificationCenter
iOS中有NSNotificationCenter可以接收Notify
以鍵盤事件的範例如下:
在viewWillAppear中註冊Notification
[sea:javaCode]
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
[/sea]
記得在viewWillDisappear中移除
[sea:javaCode]
[[NSNotificationCenter defaultCenter] removeObserver:self];
[/sea]
Actions:
[sea:javaCode]
-(void)keyboardDidShow:(NSNotification*)notif{
NSLog(@"keyboard show");
}
-(void)keyboardDidHide:(NSNotification *)notif{
NSLog(@"keyboard hide");
}
[/sea]
以鍵盤事件的範例如下:
在viewWillAppear中註冊Notification
[sea:javaCode]
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
[/sea]
記得在viewWillDisappear中移除
[sea:javaCode]
[[NSNotificationCenter defaultCenter] removeObserver:self];
[/sea]
Actions:
[sea:javaCode]
-(void)keyboardDidShow:(NSNotification*)notif{
NSLog(@"keyboard show");
}
-(void)keyboardDidHide:(NSNotification *)notif{
NSLog(@"keyboard hide");
}
[/sea]
