我尝试使用以下代码在点击时左右两侧减小RationalSet
的宽度。但相反,它只会缩小UIButton
的大小。代码是
UIButton
但输出正在缩小我不想要的 -(void)loginclickAction:(id)sender
{
self.centerZoom = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
self.centerZoom.duration = 1.5f;
self.centerZoom.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1)],[NSValue valueWithCATransform3D:CATransform3DMakeScale(.9, .9, .9)],[NSValue valueWithCATransform3D:CATransform3DMakeScale(.8,.8, .8)],[NSValue valueWithCATransform3D:CATransform3DMakeScale(.7, .7, .7)],[NSValue valueWithCATransform3D:CATransform3DMakeScale(.6, .6, .6)],[NSValue valueWithCATransform3D:CATransform3DMakeScale(.5, .5,.5)]];
self.centerZoom.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
self.loginButton.transform = CGAffineTransformMakeScale(.5,.5);
self.loginButton.alpha = 1;
[self.loginButton.layer addAnimation:self.centerZoom forKey:@"buttonScale"];
[self.loginButton setUserInteractionEnabled:NO];
}
。请帮我找到减少动画按钮宽度的方法。
答案 0 :(得分:1)
您需要一种只能在宽度上缩放按钮的方法。 使用下面的方法,通过动画将按钮从全宽度水平缩放到一半 -
-(void) reduceButtonWidthFromLeftAndRightWithAniamation:(UIButton *)button
{
[UIView beginAnimations:@"ScaleButton" context:NULL];
[UIView setAnimationDuration: 1.5f];
button.transform = CGAffineTransformMakeScale(0.5, 1.0);
[UIView commitAnimations];
}
答案 1 :(得分:1)
您的转换正在影响多个维度:
CGAffineTransformMakeScale(.5, .5);
这是缩放宽度(x)和高度(y),仅缩放宽度:
CGAffineTransformMakeScale(.5, 1);
同样适用于
CATransform3DMakeScale(.9, .9, .9)
正在改变x,y和z尺寸,应为
CATransform3DMakeScale(.9, 1, 1)