Im trying mimic messages app spring animation in a horizontal UICollectionView
I have used UIAttachmentBehavior in my UICollectionViewFlowLayout subclass. but the problem is that as I scrolls horizontally, cells also move vertically and horizontally somehow a rotational movement!
 
 

I have followed this tutorial:
implementing a bouncy uicollectionviewlayout with uikitdynamics
and used in my collectionView. I also followed WWDC 2013 session 217-Exploring Scroll Views on iOS 7. but still the problem persists!
does anyone have any idea how should I solve this?
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self){
    _dynamicAnimator = [[UIDynamicAnimator alloc] initWithCollectionViewLayout:self];
}
return self;
}
- (void)prepareLayout{
    [super prepareLayout];
    CGSize contentSize = [self collectionViewContentSize];
    NSArray *items = [super layoutAttributesForElementsInRect:CGRectMake(0, 0, contentSize.width, 500)];
    if (items.count != _dynamicAnimator.behaviors.count) {
        [_dynamicAnimator removeAllBehaviors];
        for (UICollectionViewLayoutAttributes *item in items) {
            UIAttachmentBehavior *springBehavior = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:item.center];
            springBehavior.length = 0.f;
            springBehavior.damping = 0.5f;
            springBehavior.frequency = 0.8f;
            [_dynamicAnimator addBehavior:springBehavior];
        }
    }
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
    return [_dynamicAnimator itemsInRect:rect];
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath{
    return [_dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
    CGFloat scrollDelta = newBounds.origin.x - self.collectionView.bounds.origin.x;
    CGPoint touchLocation = [self.collectionView.panGestureRecognizer locationInView:self.collectionView];
for (UIAttachmentBehavior *springBehavior in _dynamicAnimator.behaviors) {
    CGPoint anchorPoint = springBehavior.anchorPoint;
    CGFloat touchDistance = fabsf(touchLocation.x - anchorPoint.x);
    CGFloat resistanceFactor = 0.002;
    UICollectionViewLayoutAttributes *attributes = springBehavior.items.firstObject;
    CGPoint center = attributes.center;
    float resistedScroll = scrollDelta * touchDistance * resistanceFactor;
    float simpleScroll = scrollDelta;
    float actualScroll = MIN(abs(simpleScroll), abs(resistedScroll));
    if(simpleScroll < 0){
        actualScroll *= -1;
    }
    center.x += actualScroll;
    attributes.center = center;
    [_dynamicAnimator updateItemUsingCurrentState:attributes];
}
    return NO;
}
 
                        
Well I had this problem - iOS8.
Now it's gone thanks to this post.
I was adding supplementaryViews to a UICollectionView that already had UIDynamics working quite well. Then I added some supplementaryViews that were framed based on the regular cells. The calculation would return a float for the height (not 0 decimals). And I guess like Pauls said, iOS then must do some rounding which now creates a y-delta that I didn't want. This is what sets off the oscillating movement.
By rounding my supplementaryView height the problem went away. I am getting consistent centers of 7.5 so my height is not divisible by 2 but it's still working.
Here how my supplementaryViews are now calculated
All I added was the roundf to the height part of the CGRect calculation.
And voila - it is working.
Hope this helps someone - happy coding