Tracking UIView Frame Shift Animation

I have a UITextView that changes it using the animateWithDuration:animations method:

 [UIView animateWithDuration:1.5 animations:^{ [_textView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - keyboardSize.height-25)]; }]; 

Is there any callback that helps me track the height of a UITextView when animating?

+4
source share
3 answers

There is no exact way. This is because the frame is simply set directly. The animation takes care of the transition, but in fact there is no transition.

There are several ways to evaluate what the current frame size is, and for me the best thing is a simple math solution using a timer when the animation starts and the duration of the animation.

But, again, this is probably the best if you are just different, as it will certainly affect the cost and accuracy of the code.

This is my first post, and I really don’t know anything about it, just studying and trying to help.

+3
source

It depends on what you want to do with this thing.

If you want accurate information about your frame, use presentationLayer . This is a half-time view of what is actually on the screen. Please note that this is in the coordinates of the view (borders), so you need to convert it to the viewview coordinate system in order to get the current frame.

 CGRect currentTextViewFrame = [_textView.superview convertRect:[_textView.layer.presentationLayer frame] fromView:_textView]; 

Please note that this will be approximately one drawing cycle or more. If you are trying to create a new animation, this can be problematic and may cause flickering or other effects caused by the delay. In addition, at least the official documentation says that it may not always be very fast, and you may want to make the animation yourself if you need this information often because of performance reasons.

+1
source
 [_textView.layer.presentationLayer frame].size.height; 

Credit belongs to this anwser .

0
source

Source: https://habr.com/ru/post/1494399/


All Articles