Trouble with UIView, animateWithDuration and finis

2019-07-07 02:38发布

问题:

I don't know what's wrong with this piece of code.

[UIView animateWithDuration:10.0f delay:0.0f options:UIViewAnimationOptionTransitionNone animations:^{
    CGAffineTransform transform = CGAffineTransformMakeScale(0.1, 0.1);
    self.transform = transform;
}
completion:^(BOOL finished) {
    if (finished) { 
        NSLog(@"Animation finished");
        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"NSShowHomeScreen" object:nil ];
    }
}];

Even with a 10 second duration, I get the console message "Animation finished" immediately as the animation starts.

I want to shrink / scale my first UIView and after that I'd like to show another UIView. But now the 2nd UIView gets displayed well before the shrink ends.

Any help would be greatly appreciated.

Thanks

回答1:

In the UIView documentation, for the transform property, says:

Changes to this property can be animated. Use the beginAnimations:context: class method to begin and the commitAnimations class method to end an animation block. The default is whatever the center value is (or anchor point if changed)

so maybe it cant be animated using the block methods, and you will have to use begin and commit wrappers around the animation



回答2:

Sorry it was my bad. I was also using UIPinchGestureRecognizer which was causing the problems. Anyway appreciate your quick reply..

Thanks