how can I dismiss keyboard when I will just touch anywhere except UITextField?

后端 未结 10 2084
独厮守ぢ
独厮守ぢ 2021-02-19 11:12

Hello I have two UITextFields in my application, and want to dismiss the keyboard when I just touch anywhere except the UITextFields how can I do this?

10条回答
  •  Happy的楠姐
    2021-02-19 11:46

    Use this.

    - (void) animateTextField: (UITextField*) textField up: (BOOL) up
    {
    
        const int movementDistance = 180; distace of keyboard up.
    
        const float movementDuration = 0.3f;
    
         int movement = (up ? -movementDistance : movementDistance);
    
        [UIView beginAnimations: @"anim" context: nil];
        [UIView setAnimationBeginsFromCurrentState: YES];
    
        [UIView setAnimationDuration: movementDuration];
    
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    
        [UIView commitAnimations];
    }
    

提交回复
热议问题