我遇到了一些奇怪的UIView
动画。动画从矩形缩放子视图以填充其父视图:
//update views
CGRect startRect = ...; //A rect in parentView co-ordinates space that childView appears from
UIView *parentView = ...;
UIView *childView = ...;
[parentView addSubview:childView];
//animation start state
childView.alpha = 0;
childView.center = (CGPointMake( CGRectGetMidX(startRect), CGRectGetMidY(startRect)));
//TODO: set childViews transform and so that it is completely contained with in startRect
childView.transform = CGAffineTransformMakeScale(.25, .25);
[UIView animateWithDuration:.25 animations:^{
childView.transform = CGAffineTransformIdentity;
childView.alpha = 1;
childView.frame = parentView.bounds;
}];
上面的代码按预期工作。但是,如果将动画块重新排序为以下内容,则动画会变得混乱(大规模缩放并且中心点不在屏幕上):
[UIView animateWithDuration:.25 animations:^{
childView.frame = parentView.bounds; //This line was after .alpha
childView.transform = CGAffineTransformIdentity;
childView.alpha = 1;
}];
这里发生了什么?为什么属性设置的顺序对动画很重要?