简体   繁体   English

UIView动画行为不正常

[英]UIView Animation not behaving properly

I have a UIButton (size 100,100) with text and a colored background. 我有一个带有文本和彩色背景的UIButton(大小为100,100)。 When the button is pressed, I want the text to disappear immediately and the button to change size, animated, to 1000,1000. 当按下按钮时,我希望文本立即消失,并且希望按钮将动画大小更改为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). 现在,如果我取出setTitleColor ,则按钮可以很好地扩展,但是文本仍然存在(很明显)。 However, keeping setTitleColor in makes the button size 0,0 and then animates to 100,100. 但是,将setTitleColor in可使按钮大小为0,0,然后设置为100,100动画。 This also happens when I replace setTitleColor with setTitle:@"" . 当我将setTitleColor替换为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. 编辑:如果我不运行动画,而是自己执行setTitleColorsetTitle:@"" ,则文本将按预期消失,并且按钮保持相同大小。

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. 如果要保留使用UIKit设置按钮样式的方式,只需修改动画块中的图层,而不是视图即可。

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

Maybe it is even sufficient to use the view's transform property. 甚至使用视图的transform属性就足够了。

button.transform = CGAffineTransformMakeScale(10,10)

NB 10 is just an arbitrary large value. NB 10只是一个任意大的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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