简体   繁体   English

将转换后的视图添加到UIWindow或UIView后,框架错误

[英]Wrong frame after adding transformed view to UIWindow or UIView

The following code will break the frame (which will be enormous), as seen in iOS 8.1.3. 下面的代码将打破框架(这将是巨大的),如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;
}];

Removing the transformation and replacing it with a simple frame movement animation works well. 删除该转换并用简单的帧移动动画替换该转换效果很好。 Why? 为什么?

After some investigation and reasoning I came to the conclusion that it might be a good idea to apply the transformation of someView after it has been added to a view. 经过一些调查和推理,我得出的结论是,将someView的转换添加到视图中 ,可能是一个好主意。 And this turned out to be the solution. 事实证明这是解决方案。 So we write: 所以我们写:

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

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

Which works as expected. 哪个按预期工作。

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

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