我有一个长度增长的动画矩形:
[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
}];
然而,矩形只会改变它的高度,使其向下而不是向上。如何更改它以使矩形长大?
答案 0 :(得分: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.
}];
}