ios – UIView transitionFromView:toView:和布局约束

前端之家收集整理的这篇文章主要介绍了ios – UIView transitionFromView:toView:和布局约束前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
什么是正确的方式使用[UIView transitionFromView:toView:…]与布局约束?

我想在superview约束toView中安装约束.在转换调用之前,我无法做到,因为View还没有超级视图. (在调用之后但在运行循环进行之前相同)等待直到完成块安装它意味着该视图将具有动画而没有约束.

解决方法

我将使用UIViewAnimationOptionShowHideTransitionViews选项,它允许toView和fromView在转换之前在视图层次结构中,但显示一个并隐藏另一个.

将toView设置为隐藏,将其添加到超级视图中,并在转换之前安装约束.然后,您可以删除完成块中的旧视图.这样的东西

[toView setHidden: YES];
[containerView addSubview: toView];
[containerView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @"|[toView]|" options: 0 metrics: nil views: NSDictionaryOfVariableBindings(containerView,toView)]];
[containerView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|[toView]|" options: 0 metrics: nil views: NSDictionaryOfVariableBindings(containerView,toView)]];

[UIView transitionFromView: fromView toView: toView duration: 1.0 options: UIViewAnimationOptionTransitionFlipFromBottom | UIViewAnimationOptionShowHideTransitionViews completion:^(BOOL finished) {
    [fromView removeFromSuperview];
}];
原文链接:https://www.f2er.com/iOS/329971.html

猜你在找的iOS相关文章