我可能做错了,但以下似乎在一个简短的例子中起作用:
为有问题的项目分配 UIDynamicItemBehavior:
self.itemBehaviorInQuestion = [[UIDynamicItemBehavior alloc] initWithItems:@[self.infoView]];
self.itemBehaviorInQuestion.resistance = 0;
self.collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.infoView]];
self.collisionBehavior.collisionDelegate = self;
[self.animator addBehavior:self.collisionBehavior];
[self.animator addBehavior:self.itemBehaviorInQuestion];
实现以下 UICollisionBehavior 委托方法:
- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p
{
self.itemBehaviorInQuestion.resistance = 100;
}
- (void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier
{
self.itemBehaviorInQuestion.resistance = 0;
}
在那一刻将阻力设置为高值似乎可以减轻项目的反弹。