如何通过编程方式找出键盘向下箭头键

时间:2022-06-26 08:51:51

I know that when down arrow key is pressed on keyboard then we can get Keyboard Hide notification but the problem is, we get Keyboard Hide notification also when we rotate the device and keyboard hides, now how to differentiate that keyboard is hiding because of key pressed not because of rotation.如何通过编程方式找出键盘向下箭头键

我知道当键盘上按下向下箭头键时我们可以获得键盘隐藏通知但问题是,当我们旋转设备和键盘隐藏时我们也得到键盘隐藏通知,现在如何区分键盘因按键而隐藏不是因为轮换。

2 个解决方案

#1


3  

In your AppDelegate.m

在你的AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
      [[NSNotificationCenter defaultCenter] 
      addObserver:self selector:@selector(keyboardWillHide) 
      name:UIKeyboardWillHideNotification object:nil];
      return YES;
}


-(void) keyboardWillHide {
  NSLog(@"Bye");
}

#2


0  

Following Delegate method of textfield is called automatically when we clicked on the return or arrow button of keyboard.

当我们点击键盘的返回或箭头按钮时,会自动调用文本字段的Delegate方法。

- (BOOL)textFieldShouldReturn:(UITextField *)textField

#1


3  

In your AppDelegate.m

在你的AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
      [[NSNotificationCenter defaultCenter] 
      addObserver:self selector:@selector(keyboardWillHide) 
      name:UIKeyboardWillHideNotification object:nil];
      return YES;
}


-(void) keyboardWillHide {
  NSLog(@"Bye");
}

#2


0  

Following Delegate method of textfield is called automatically when we clicked on the return or arrow button of keyboard.

当我们点击键盘的返回或箭头按钮时,会自动调用文本字段的Delegate方法。

- (BOOL)textFieldShouldReturn:(UITextField *)textField