1

我有一个长度增加的动画矩形:

[UIView animateWithDuration:60
                 animations:^{
                 CGRect frame = left.frame;
                 // adjust size of frame to desired value
                 frame.size.height -= 0.1;
                 left.frame = frame; // set frame on your view to the adjusted size
                 }
                 completion:^(BOOL finished){
                 // Re-start the animation if desired
                 }];

但是,矩形只会改变它的高度,使其向下而不是向上。如何更改它以使矩形向上增长?

4

1 回答 1

1

你只是改变框架的高度。这将保持相同的 x 和 y 原点值。

您需要更改高度和原点,例如 htis ...

[UIView animateWithDuration:60
                 animations:^{
                     CGRect frame = left.frame;
                     // adjust size of frame to desired value
                     frame.size.height -= 0.1;
                     frame.origin.y += 0.1; // make opposite to origin as to height
                     left.frame = frame; // set frame on your view to the adjusted size
                 }
                 completion:^(BOOL finished){
                     // Re-start the animation if desired
                 }];

从零高度循环到 100 高度(例如)

- (void)animateHeight
{
    [UIView animateWithDuration:60
                          delay:0.0
                        options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
                     animations:^{
                         CGRect frame = left.frame;
                         // adjust size of frame to desired value
                         frame.size.height = 100;
                         frame.origin.y -= 100; // make opposite to origin as to height
                         left.frame = frame; // set frame on your view to the adjusted size
                     }
                     completion:^(BOOL finished){
                         // animation is auto reversing and repeating.
                     }];
}
于 2013-05-19T19:55:57.180 回答