如果我在视图中添加任何类型的内容UIDynamicBehavior
,它会在设备旋转时完全破坏。这是纵向的(正确显示):
这里是风景,一切都坏了:
我不相信这是一个自动布局问题,因为如果我删除添加的调用UIDynamicBehavior
它可以正常工作而没有自动布局问题。也不会抛出任何自动布局错误。这是代码:
@interface SWViewController () {
UICollisionBehavior *coll;
UIDynamicAnimator *dynamicAnimator;
}
@implementation SWViewController
- (void)viewDidLoad {
[super viewDidLoad];
dynamicAnimator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self setupCollisions]; // commenting this out fixes the layout
}
- (void)setupCollisions {
NSArray *dynamicViews = @[greenView];
coll = [[UICollisionBehavior alloc] initWithItems:dynamicViews];
CGFloat topBound = CGRectGetMinY(greenView.frame);
[coll addBoundaryWithIdentifier:@"top"
fromPoint:CGPointMake(0, h1)
toPoint:CGPointMake(CGRectGetWidth(greenView.frame), h1)];
[dynamicAnimator addBehavior:coll];
}
如果我重写didRotateFromInterfaceOrientation
,我可以看到顶部边界greenView
不遵循自动布局所说的(再次,删除setupCollisions
修复此问题的调用)。
上的自动布局边界greenView
是:
height = 200
trailing space to Superview = 0
leading space to Superview = 0
bottom space to Superview = 0