简体   繁体   中英

UIView Animation not behaving properly

I have a UIButton (size 100,100) with text and a colored background. When the button is pressed, I want the text to disappear immediately and the button to change size, animated, to 1000,1000. Here is the code I'm using:

    [myButton setTitleColor:[UIColor colorWithRed:195/255.0f green:255/255.0f blue:180/255.0f alpha:0.0f] forState:UIControlStateNormal];

    [UIView animateWithDuration:2.0f
                          delay:1.0f
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{

                     [myButton setBounds:CGRectMake(0, 0, 1000, 1000)];

                     }
                    completion:^(BOOL finished){
                     SetupView * sv = [[SetupView alloc] initWithNibName:nil bundle:nil];
                     //[self presentViewController:sv animated:NO completion:nil];

                 }
 ];

Now, if I take out setTitleColor , the button expands just fine, but the text is still there (obviously). However, keeping setTitleColor in makes the button size 0,0 and then animates to 100,100. This also happens when I replace setTitleColor with setTitle:@"" . I've also tried changing the text or color in the animation with the same result.

I feel like it's something obvious I've missed, but I can't seem to see it.

edit: If I don't run the animation and just do setTitleColor or setTitle:@"" by themselves, the text disappears as expected and the button stays the same size.

If you want to preserve the way you used UIKit to style your button, just modify the layer in the animation block, not the view.

 button.layer.transform = CATransform3DMakeScale(10,10,1)

Maybe it is even sufficient to use the view's transform property.

button.transform = CGAffineTransformMakeScale(10,10)

NB 10 is just an arbitrary large value.

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