Reputation: 1
When I add some animations on the subview of the scrollview that like extending or contract a textfield,it just not work. But it worked well when the subview add to a simple UIView.
How did it happen?
Upvotes: 0
Views: 438
Reputation: 437622
There should be no problem animating the frame
of a UITextField
within a UIScrollView
.
The most common source of "my animation isn't animating" in iOS 6 and later is the attempt to animate a control by adjusting the frame
when employing autolayout (because the adjustment of the frame
can be thwarted by the constraints being reapplied by the most innocuous of actions). You can tell if you're using autolayout or not by selecting the File Inspector (the first tab) of the rightmost panel in Interface Builder, and seeing if "Use Autolayout" is checked:
For example, to animate the frame
when not using autolayout, assuming your UITextField
has an IBOutlet
called textField
, you might do something like:
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = self.textField.frame;
frame.size.width = 280;
self.textField.frame = frame;
}];
But the equivalent when using autolayout is not achieved by adjusting the frame
, but rather by changing the constraints' constant
values. For example, assuming you created an IBOutlet
for the width
constraint called textFieldWidthConstraint
on your UITextField
, you would animate the changing of the width with something like:
self.textFieldWidthConstraint.constant = 280;
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
If you believe you are using the appropriate animation technique that corresponds to your choice of autolayout or non-autolayout, but it's still not working, you should show us some code and describe the situation in greater detail.
Upvotes: 1