简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM