Become first responder without animation

前端 未结 3 668
無奈伤痛
無奈伤痛 2021-02-13 18:31

Is there a way for a UITextField to become first responder without the animation of the keyboard? That is, make it such that the keyboard just appears?

Basi

3条回答
  •  迷失自我
    2021-02-13 19:03

    You can use a UIView animation like so

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.0];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    
    [textField becomeFirstResponder];  // <---- Only edit this line
    
    [UIView commitAnimations];
    

    This will cause the keyboard to suddenly appear.

    You can do the same but with -resignFirstResponder

    Swift ..

        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(0.0)
        UIView.setAnimationDelay(0.0)
        someTextView.resignFirstResponder()
        UIView.commitAnimations()
    

提交回复
热议问题