简体   繁体   中英

about the animation on the subview of UIScrollView

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM