3

I have been trying to get to the bottom of this, and it escapes me. I have some buttons I want to ide when the user presses them. But instead of just hiding them, I want an animation. I am making them grow in size, before shrinking to a pinhead whilst also fading out.

I actually have this working as I desire in iOS6, but thought I would run it in a simulator for iOS5.1 and on my iPad1. Both of which make the button animation buggy. It grows, but then seems to explode into another dimension on the screen.

#pragma mark - animations
-(void)grow:(UIButton *)button {

    void (^makeItGrow)(void)= ^{
        button.transform = CGAffineTransformScale(button.transform,1.6, 1.6);
    };

    void (^whenFinished)(BOOL) =
    ^(BOOL finished) {
        if (finished) {
            [self shrink:button];
        }
    };

    [UIView animateWithDuration:1 animations:makeItGrow completion:whenFinished];

}

-(void)shrink:(UIButton *)button {
    void (^makeItShrink)(void)= ^{

        button.transform = CGAffineTransformScale(button.transform, 0.0, 0.0);
        button.alpha = 0.0;
    };

    void (^whenFinished)(BOOL) =
    ^(BOOL finished) {
        if (finished) {
            //NSLog(@"shrink finished");
            [button setHidden:YES];
            [self resetButton:button];
        }
    };

    [UIView animateWithDuration:3 animations:makeItShrink completion:whenFinished];
}

I have slowed the animation down just so I could see it clearer. The first section does as it should, but the second section (the shrink) either splinters into the screen (you have to see it, it's does look kinda cool), or it simply continues to grow OUT of the screen! Certainly not what's desired.

And yes, I am still very much learning, I could probably take some pointers on my coding style :-)

4

1 回答 1

6

尝试设置非常低但不等于零比例因子。

button.transform = CGAffineTransformScale(button.transform, 0.0001, 0.0001);
于 2012-11-27T14:40:28.400 回答