自动布局,屏幕旋转和动画的UIView [英] Auto layout, screen rotation and UIView animation

查看:258
本文介绍了自动布局,屏幕旋转和动画的UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我添加到屏幕的底部,它的动画,以填补大部分屏幕如果一个按钮pssed $ P $一个UIView的问题。该视图将动画上下和旋转预期。如果我尝试在景观动画的同时,它打破了,给我的错误信息:

I am having an issue with a UIView that I add to the the bottom of the screen and animate it up to fill most of the screen if a button is pressed. The view will animate up and down and rotates as intended. If I try to animate while in landscape, it breaks and gives me error message:

*** Assertion failure in -[UIScrollView _edgeExpressionInContainer:vertical:max:], /SourceCache/UIKit_Sim/UIKit-2380.17/NSLayoutConstraint_UIKitAdditions.m:2174
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Autolayout doesn't support crossing rotational bounds transforms with edge layout constraints, such as right, left, top, bottom. The offending view is: <UIView: 0x9199340; frame = (20 0; 748 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0x91993d0>>'

有问题的看法是self.view。

The offending view is self.view.

我如何创建UIView的:

How I create the UIView:

[self.myContentView addSubview:subBar.filterListView];

[self.myContentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[filterListView]|"
                                                                           options:0
                                                                           metrics:nil
                                                                             views:@{@"filterListView": subBar.filterListView}]];

subBar.filterListView.bottomConstraint = [NSLayoutConstraint constraintWithItem:subBar.filterListView
                                                                      attribute:NSLayoutAttributeBottom
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:self.mapView
                                                                      attribute:NSLayoutAttributeBottom
                                                                     multiplier:1
                                                                       constant:0];

subBar.filterListView.topConstraint = [NSLayoutConstraint constraintWithItem:subBar.filterListView
                                                                   attribute:NSLayoutAttributeTop
                                                                   relatedBy:NSLayoutRelationEqual
                                                                      toItem:self.mapView
                                                                   attribute:NSLayoutAttributeBottom
                                                                  multiplier:1
                                                                    constant:0];

[self.myContentView addConstraint:subBar.filterListView.bottomConstraint];
[self.myContentView addConstraint:subBar.filterListView.topConstraint];

self.myContentView是占据了整个self.view一个UIView:

self.myContentView is a UIView that takes up the whole self.view:

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:NSDictionaryOfVariableBindings(contentView)]];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|"
                                                                         options:0
                                                                         metrics:nil
                                                                           views:NSDictionaryOfVariableBindings(contentView)]];    

要动画的subBar.filterListView,我删除顶部和底部的约束,重新分配,添加它们,和动画:

To animate the the subBar.filterListView, i remove the top and bottom constrain, reassign them, add them, and animate:

[self.myContentView removeConstraint:view.topConstraint];
[self.myContentView removeConstraint:view.bottomConstraint];

view.topConstraint = [NSLayoutConstraint constraintWithItem:view
                                                  attribute:NSLayoutAttributeTop
                                                  relatedBy:NSLayoutRelationEqual
                                                     toItem:self.topToolBar
                                                  attribute:NSLayoutAttributeBottom
                                                 multiplier:1
                                                   constant:0];

view.bottomConstraint.constant -= SUB_BAR_SIZE.height;

[self.myContentView addConstraint:view.topConstraint];
[self.myContentView addConstraint:view.bottomConstraint];

[self.myContentView setNeedsUpdateConstraints];

[UIView animateWithDuration:.25 animations:^{
    [self.myContentView layoutIfNeeded];
}];

时的code得到顶部和底部的困惑,当它旋转?是否觉得画像上方是横向的左?

Is the code getting confused with top and bottom when it rotates? Does it think the portrait top is the landscape's left?

推荐答案

好吧,我找到了解决办法。它不解决上述问题,而是发现了另一种方式来处理它。

Ok, I found a solution. It doesn't fix the above issue, but rather found another way to approach it.

我改变了我的限制到Visual格式语言(VFL)方法:

I changed my constraints to the Visual Format Language (VFL) method instead:

subBar.filterListView.verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[filtersSubBar][filterListView(0)]" options:0
                                                                                    metrics:nil
                                                                                      views:@{@"filterListView": subBar.filterListView, @"filtersSubBar" : subBar.filtersSubBar}];

我认为这个问题是使用是造成这一问题的属性 NSLayoutAttributeTop NSLayoutAttributeRight 等。

自动布局无法处理旋转,并试图使用 NSLayoutAttributeTop 当它应该已被更改为 NSLayoutAttributeRight 给前preSS的新方向。我想我们可以手动更改约束。

Autolayout couldn't handle the rotation and trying to use the NSLayoutAttributeTop when it should have been changed to NSLayoutAttributeRight to express the new orientation. I suppose we could manually change the constraint.

看来VFL不同的方式处理它并没有使用属性?

It seems the VFL handles it differently and does not use the attributes?

这感觉好像不是它的一个bug或只是一个iOS版的缺点。

This feels as if its either a bug or just a shortcoming of iOS.

这篇关于自动布局,屏幕旋转和动画的UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆