【发布时间】:2013-09-20 03:18:48
【问题描述】:
我正在像这样向动画师添加视图:
-(void)drawCellLikeViews{
//2. Add Animator
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self];
//Alloc array
viewsArray = [[NSMutableArray alloc] initWithCapacity:6];
for (int numberOfViews = 0; numberOfViews < 5; numberOfViews++) {
//Create views
UIView* cell = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
cell.backgroundColor = [UIColor grayColor];
[self addSubview:cell];
[viewsArray addObject:cell];
}
//3. Add Gravity
_gravity = [[UIGravityBehavior alloc] initWithItems:viewsArray];
[_animator addBehavior:_gravity];
//4. Add boundaries
_collision = [[UICollisionBehavior alloc] initWithItems:viewsArray];
_collision.translatesReferenceBoundsIntoBoundary = YES;
[_animator addBehavior:_collision];
//8. Add ItemProperties' Behaviors
UIDynamicItemBehavior* itemBehaviour = [[UIDynamicItemBehavior alloc] initWithItems:viewsArray];
itemBehaviour.elasticity = 0.6;
//9. itemBehaviour.action = ^{};
[_animator addBehavior:itemBehaviour];
NSLog(@"viewcount %d", [[self subviews] count]);
}
我只看到一个下拉到底部。
【问题讨论】:
-
你看到其他人没有下拉吗?因为看起来它们都是从同一个地方开始的,并且具有相同的行为,所以它们会一致地移动并相互叠加,给人一种物体坠落的感觉。
-
是的,我就是这样“修复”它的。我只是想知道为什么,如果他们相互反应,即使他们都从同一个地方开始,他们最终不会堆叠起来。
-
似乎它们与边缘碰撞相互作用,而不是理解它们占据相同的空间并相应地调整它们的位置。