开发者

UIView animation change size of button

开发者 https://www.devze.com 2023-03-25 00:36 出处:网络
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 expa开发者_StackOverflow中文版nding. So far I have this

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 expa开发者_StackOverflow中文版nding. 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?

EDIT:

- (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];
}


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];
//}];
0

精彩评论

暂无评论...
验证码 换一张
取 消