UIView动画更改按钮的大小 [英] UIView animation change size of button
问题描述
我开始尝试在应用商店中重新创建购买"按钮,这需要两步点击才能购买商品.我为按钮扩展动画.到目前为止,我有这个
I started trying to recreate the buy button from the app store which requires a 2-stage click to buy something. I to animate the button expanding. So far I have this
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);
[UIView commitAnimations];
这只会导致按钮变大,根本没有动画.我做错了什么吗,还是其他人实现了这种按钮行为?
which just causes the button to become larger, it doesn't animate at all. Have I done something wrong or has anyone else implemented this type of button behaviour?
- (IBAction) buyButtonAction: (UIButton *) sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
sender.clipsToBounds = NO;
sender.frame = CGRectMake( CGRectGetMinX( sender.frame) - 30, CGRectGetMinY(sender.frame), 200, 37);
[sender setTitle:@"Touched Touched Touched" forState:UIControlStateNormal];
[UIView commitAnimations];
}
推荐答案
您是否要定位不支持Blocks的iOS?
Are you targeting an iOS that doesn't support Blocks?
我使用以下令人讨厌的简单代码实现了触摸时设置动画".
I've implemented a "button animates on touch" using the following nauseatingly simple code.
[UIView animateWithDuration:0.5 animations:^{
self.navigationItem.rightBarButtonItem.title = @"Quoting...";
}];
或者,如果您不支持方块,此代码似乎也可以使触摸按钮上的动画效果更好(如果您选择该路线,它还包括注释掉的方块):
Alternatively, this code seems to work as well to animate a button on touch, if you can't support blocks (it also includes the blocks commented out if you go that route):
-(IBAction) clicked:(UIButton*)sender{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//[UIView animateWithDuration:2.5 animations:^{
sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);
//sender.frame = CGRectMake( CGRectGetMinX( self.theButton.frame) - 100, CGRectGetMinY(self.theButton.frame), 300, 40);
//[sender setTitle:@"Touched Touched Touched" forState:UIControlStateNormal];
//}];
这篇关于UIView动画更改按钮的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!