如何在调整UIView大小时进行动画 [英] How to animate while resizing UIView
问题描述
我在网上看到了一些材料,但仍然不能到达我想要的地方。
我需要动画我的视图向下,使它的高度更大。
I saw some material on the web, but still can't quite get to where I want. I need to animate my view downwards, making it's height bigger.
这里是我的代码到目前为止。这里发生了什么,是,而不是我的视图调整大小,它只是改变它的位置有点。
如果我将proprty而不是bounds.size改为transform.scale.y,它会更好一点,只有这次它向上和向下扩展视图,而不只是向下扩展。
Here is my code so far. What's happening here, is that instead of my view resizing, it's just changing it's location a bit up. If I change the proprty instead of "bounds.size" to be "transform.scale.y", it's a little better, only this time it expands the view both up and down, not just downwards.
另一件我不是:这些键只是CALayer属性?在哪里可以找到这些键的列表?
Another thing I'm not of : are these keys just CALayer properties ? where I can find a list of these keys?
我真的很感谢在这里的帮助。谢谢!
I would really appreciate help here. Thanks!
int x = self.btnHead.frame.origin.x;
int y = self.btnHead.frame.origin.y;
int height = self.btnHead.frame.size.height;
int width = self.btnHead.frame.size.width;
CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(width,height+50)]];
resizeAnimation.fillMode = kCAFillModeForwards;
resizeAnimation.removedOnCompletion = NO;
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = [NSArray arrayWithObjects:resizeAnimation,nil];
animationGroup.removedOnCompletion = NO;
animationGroup.fillMode = kCAFillModeForwards;
animationGroup.removedOnCompletion=NO;
animationGroup.duration = 0.1;
[self.btnHead.layer addAnimation:animationGroup forKey:@"animations"];
修改:根据请求发布我的第一个代码 -
posting my first code as requested - This will just change my view size, but won't animate , no matter the duration I enter.
int x = self.btnHead.frame.origin.x;
int y = self.btnHead.frame.origin.y;
int height = self.btnHead.frame.size.height;
int width = self.btnHead.frame.size.width;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:10];
CGRect rect = CGRectMake(x,y,width ,height+BUTTON_HEIGH*2);
self.btnHead.frame = rect;
[UIView commitAnimations];
推荐答案
btnHead.clipsToBounds=YES
解决了问题。
不确定exacly为什么。
Solved the issue. Not sure exacly why.
这篇关于如何在调整UIView大小时进行动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!