UIButton改变大小与中心

时间:2013-09-14 18:26:19

标签: ios

我以这种方式动画UIButton的宽度和高度的变化:

[UIView animateWithDuration:0.5
delay:0.0
                                    options: UIViewAnimationCurveEaseInOut
                                 animations:^{

                                     CGRect frame = [[sender view] frame];
                                     frame.size.width = 0;
                                     frame.size.height = 0;
                                     [[sender view] setFrame:frame];

                                 }
                                 completion:^(BOOL finished){

}];

按钮正在改变尺寸,但我希望它关闭它的中心,而不是它的角落。我知道这是因为它关闭了x和y坐标,但是我可以将它关闭到中心吗?

2 个答案:

答案 0 :(得分:4)

这就是你想要的动画块:

[sender view].frame = (CGRect){[[sender view] center],CGSizeZero};

答案 1 :(得分:2)

怎么样:

[UIView animateWithDuration:0.5
delay:0.0
                                options: UIViewAnimationCurveEaseInOut
                             animations:^{

                                 CGRect frame = [[sender view] frame];

                                 frame.origin.x += frame.size.width / 2.0f;
                                 frame.origin.y += frame.size.height / 2.0f;
                                 frame.size.width = 0;
                                 frame.size.height = 0;
                                 [[sender view] setFrame:frame];

                             }
                             completion:^(BOOL finished){

}];