swi*_*ams 5 autolayout ios7 uicollisionbehavior uidynamicbehavior uikit-dynamics
如果我在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];
}
Run Code Online (Sandbox Code Playgroud)
如果我覆盖didRotateFromInterfaceOrientation我可以看到顶部边界greenView不遵循autolayout所说的应该(再次,删除调用以setupCollisions修复此问题).
自动布局边界greenView是:
height = 200
trailing space to Superview = 0
leading space to Superview = 0
bottom space to Superview = 0
Run Code Online (Sandbox Code Playgroud)
我发现的一种解决方案是覆盖willRotateToInterfaceOrientation:并删除UIDynamicItems,然后将它们重新添加到didRotateFromInterfaceOrientation:. 这让我觉得相当老套,一旦我添加更复杂的行为,可能会引入错误。
| 归档时间: |
|
| 查看次数: |
1384 次 |
| 最近记录: |