Typing while animation UITextView

2019-02-11 05:32发布

问题:

I'm trying to have a variable-height UITextView which changes size to accomodate its contents, but when the frame changes in the size-change animation, one or two keystrokes aren't captured in the UITextView. The animation duration is 0.1s, and typically it only misses one letter when you're typing fairly fast. It is, however, very consistent in missing letters when the animation happens. The following animation block occurs within the textViewDidChange: delegate message:

[UIView animateWithDuration:0.1 animations:^{

    [textView setFrame:CGRectMake(...)];

}];

I've Googled and searched on SO, but so far nothing has come up. Has anyone else encountered this?

回答1:

By default UIView animations disable user interaction for animated view, so possibly (sorry cannot test it now) explicitly enabling user interaction will solve your problem:

[UIView animateWithDuration:0.1 
        delay:0.0
        options: UIViewAnimationOptionAllowUserInteraction
        animations:^{    
            [textView setFrame:CGRectMake(...)];
        }    
        completion:^(void){}];