简体   繁体   中英

Strange Wobble effect on iPhone 6 Plus simulator - UIDynamics

Video link here: (low quality) where you can see everything wobbling around. https://drive.google.com/file/d/0B6SrhxQY65faS3pfaGF0bXBiVXFncWU0aFdsVWFpUXEwaXJ3/edit?usp=sharing

Fix mentioned below doesn't work when in native (non scaling mode), so not really fix.

[Update] So setting a one pixel section inset on the collection view (I had zero left and right before), makes the weirdness go away, it's really strange, why does this only happen on the iPhone 6 Plus? I don't like how it looks with the single pixel inset so will leave the question open in case someone knows what might be going on.

[Original Question] I am using UIAttachmentBehaviors in my UICollectionView that provide a stretchy feel when browsing the collection. This works fine everywhere, except in the iPhone 6 Plus simulator (on XCode 6.0.1). On iPhone 6 Plus, the collection items rotate and wobble around (when they should only be moving on the Y axis. They continue to move for about a minute and then very slowly settle down, while the actual animation is only supposed to last for a fraction of a second. They show clear X axis movement. Has anyone else noticed similar weirdness with the iPhone 6 plus? I'm wondering if this is a simulator bug or a real issue but don't have an iPhone 6 Plus to test on. It works fine on the iPhone 6 simulator.

My code looks like this, and I can't see how this could cause X coordinate changes:

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
UIScrollView *scrollView = self.collectionView;
CGFloat delta = newBounds.origin.y - scrollView.bounds.origin.y;


CGPoint touchLocation = [self.collectionView.panGestureRecognizer   locationInView:self.collectionView];

[self.dynamicAnimator.behaviors enumerateObjectsUsingBlock:^(UIAttachmentBehavior *springBehaviour, NSUInteger idx, BOOL *stop) {
    CGFloat yDistanceFromTouch = fabsf(touchLocation.y - springBehaviour.anchorPoint.y);
    CGFloat xDistanceFromTouch = fabsf(touchLocation.x - springBehaviour.anchorPoint.x);
    CGFloat scrollResistance = (yDistanceFromTouch + xDistanceFromTouch) / 1500.0f;

    UICollectionViewLayoutAttributes *item = springBehaviour.items.firstObject;
    CGPoint center = item.center;
    if (delta < 0) {
        center.y += MAX(delta, delta*scrollResistance);
    }
    else {
        center.y += MIN(delta, delta*scrollResistance);
    }
    item.center = center;

    [self.dynamicAnimator updateItemUsingCurrentState:item];
}];

return NO;
}

I have the same problem when trying to use UICollectionView with UIKit Dynamics .

Problem seems to appears when you compute size of items programmatically to fit width of screen, so in this case items interfere with each other while dynamics applies and cannot get to equilibrium. (so this is like corner case when items actually overlaps)

In my case solution is simple - I just decrease size of items to be around 90% of computed value. It will impose some gap between items, but this is doesn't matter in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM