0

我以这种方式为 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 坐标上关闭,但我可以让它关闭到中心吗?

4

2 回答 2

4

这是您在动画块中想要的:

[sender view].frame = (CGRect){[[sender view] center],CGSizeZero};
于 2013-09-14T18:57:53.360 回答
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){

}];
于 2013-09-14T18:37:03.450 回答