Background
I am working on a quick and dirty notes app to try and understand autorun. Therefore, I am looking for a solution to solve this problem.
I am quite sure that my terminology and understanding of this subject may be wrong in places, therefore, if I am wrong or omit information from ignorance that would otherwise be useful, I am very happy to update this question with better features.
Brief Description of the Problem
- This app is a simple note taking app. In the note detail view, there are two text input views, UITextField and UITextView.
- The goal is to use autostart to animate the change in height in the UITextView when editing it (making room for the keyboard), and then update the UITextView to its original size when editing is complete.
- The animation code that I have works, however, when the UITextView scrolls near the bottom of the text, the animation with the size "edit" to the "uneditable" size does not display correctly, bullying the animation. (The end result of the animation, however, is correct.)
- I am open to alternative βrightβ ways to do this if there is a common template for the solution. However, I am looking for an autorun solution, which I believe means that you should not directly change the presentation frame. (Perhaps this is wrong).
Details and code
A short video of the problem is available here:
http://pile.cliffpruitt.com/m/constraint_problem.mp4
This is the animation code:
// self.bodyFieldConstraintBottom refers to an outlet referencing the UITextView bottom constraint // This animation occurrs when the text view is tapped - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { [self enterEditingMode]; [UIView animateWithDuration:2.35 animations:^{ NSLayoutConstraint *bottom_constraint = self.bodyFieldConstraintBottom; bottom_constraint.constant = 216; [self.view layoutIfNeeded]; }]; return YES; } // This animation occurrs when editing ends and the text field size is restored - (BOOL)textViewShouldEndEditing:(UITextView *)textView { [self exitEditingMode]; [UIView animateWithDuration:2.35 animations:^{ NSLayoutConstraint *bottom_constraint = self.bodyFieldConstraintBottom; bottom_constraint.constant = 20; [self.view layoutIfNeeded]; }]; return YES; }
The full source of the project (in all its dirty glory) can be downloaded here:
http://pile.cliffpruitt.com/dl/LittleNotebooks.zip
Additional comments
My understanding of cocoa terminology is not the best, so itβs hard for me to find effective Google searches and document searches. My best guess about the problem (based on watching the animation at a slow speed) is that it is related to the scroll shift anyway, because if the text does not scroll past a certain point, the problem does not appear.
I read quite a few questions and answers, including:
The problem is that these answers either do not work ([self.bodyField setContentInset: UIEdgeInsetsMake (0, 0, 216, 0)] does not seem to have any effect) or seem to rely on setting a UIText presentation frame which, like I suppose it should not be executed when using autorun.
Final side note
I worked for about 4 days, so my understanding and remembrance of everything that I read and tried was actually a little less clear than when I started. Hopefully I will explain it well enough to convey this issue.
EDIT:
I noticed that this code actually comes a little closer to the desired result:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView { [self enterEditingMode]; [UIView animateWithDuration:2.35 animations:^{ [self.bodyField setContentInset:UIEdgeInsetsMake(0, 0, 216, 0)]; [self.view layoutIfNeeded]; }]; return YES; } - (BOOL)textViewShouldEndEditing:(UITextView *)textView { [self exitEditingMode]; [UIView animateWithDuration:2.35 animations:^{ [self.bodyField setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; [self.view layoutIfNeeded]; }]; return YES; }
The problem with this version is that the scroll indicator scrolls past the visible area of ββthe text content, which means that it is lost behind the key. Also, this does not help me understand the correct way to animate the lower bound of a UITextView (UIScrollView?).