鍵盤事件 - 使用NSNotificationCenter
發表人:
Seachaos
積分: 2432
積分: 2432
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]
同步發表於 程式植物園