UITableViewCell中的UIAttachmentBehavior就像Messages App一样

时间:2014-01-06 13:44:51

标签: ios objective-c uitableview uikit

我想复制UITableViewCell的附件行为,就像Apple在消息应用程序中所做的那样。

我尝试了子类化UITableViewCell,这里是代码:

    self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self];

self.attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.superview attachedToAnchor:self.superview.center];
[self.attachmentBehavior setFrequency:4.5];
[self.attachmentBehavior setDamping:0.3];

UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[self]];

//gravity direction: right
[gravityBehavior setGravityDirection:CGVectorMake(0.0, -0.8)];

UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self]];
[collisionBehavior addBoundaryWithIdentifier:@"topBoundary" fromPoint:CGPointMake(0.0f, 0.0f) toPoint:CGPointMake(self.contentView.frame.size.width, 0.0f)];
[collisionBehavior addBoundaryWithIdentifier:@"bottomBoundary" fromPoint:CGPointMake(0.0f, self.contentView.frame.size.height) toPoint:CGPointMake(self.contentView.frame.size.width, self.contentView.frame.size.height)];

UIDynamicItemBehavior* itemBehaviour = [[UIDynamicItemBehavior alloc] initWithItems:@[self]];
itemBehaviour.elasticity = 0.9;
[self.animator addBehavior:itemBehaviour];

[self.animator addBehavior:gravityBehavior];
[self.animator addBehavior:collisionBehavior];

但是,它似乎不起作用。

有人可以帮我重现与消息应用程序相同的功能吗?

编辑:
我知道Apple使用UICollectionView而不是tableview作为Messages App,但我希望有一种方法可以通过tableview来实现这种功能。

0 个答案:

没有答案