将转换后的视图添加到UIWindow或UIView后错误的帧

时间:2016-04-12 10:30:06

标签: ios objective-c animation uiview uiwindow

以下代码将破坏框架(这将是巨大的),如iOS 8.1.3中所示。

someView.layer.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
[[[[UIApplication sharedApplication] keyWindow].subviews lastObject] addSubview:someView];

[UIView animateWithDuration:0.3f animations:^{
    someView.transform = CATransform3DIdentity;
}];

删除转换并用简单的帧移动动画替换它很有效。为什么呢?

1 个答案:

答案 0 :(得分:0)

经过一些调查和推理后,我得出的结论是,在将添加到视图中之后应用someView 的转换可能是个好主意。结果证明这是解决方案。所以我们写道:

[[[[UIApplication sharedApplication] keyWindow].subviews lastObject] addSubview:someView];
someView.layer.transform = CGAffineTransformMakeScale(0.001f, 0.001f);

[UIView animateWithDuration:0.3f animations:^{
    someView.transform = CGAffineTransformIdentity;
}];

按预期工作。