我像这样向动画师添加视图:
-(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]);
}
我只看到一个下降到底部。