【发布时间】:2014-09-18 10:48:10
【问题描述】:
此处的视频链接:(低质量)您可以在其中看到一切摇摆不定的东西。 https://drive.google.com/file/d/0B6SrhxQY65faS3pfaGF0bXBiVXFncWU0aFdsVWFpUXEwaXJ3/edit?usp=sharing
下面提到的修复在原生(非缩放模式)下不起作用,所以没有真正修复。
[更新] 所以在集合视图上设置一个像素的部分插入(我之前左右都是零),让怪异消失了,真的很奇怪,为什么这只发生在iPhone 6 Plus?我不喜欢单像素插图的外观,所以如果有人知道可能发生的情况,我会留下问题。
[原始问题]我在我的 UICollectionView 中使用 UIAttachmentBehaviors,它在浏览集合时提供了一种有弹性的感觉。除了在 iPhone 6 Plus 模拟器(在 XCode 6.0.1 上)之外,这在任何地方都可以正常工作。在 iPhone 6 Plus 上,收集项目旋转和摆动(当它们应该只在 Y 轴上移动时。它们继续移动大约一分钟,然后非常缓慢地稳定下来,而实际动画应该只持续一分钟)几分之一秒。它们显示出清晰的 X 轴运动。有没有其他人注意到 iPhone 6 plus 有类似的怪异之处?我想知道这是模拟器错误还是真正的问题,但没有 iPhone 6 Plus 可以测试. 它在 iPhone 6 模拟器上运行良好。
我的代码看起来像这样,我看不出这会如何导致 X 坐标变化:
-(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;
}
【问题讨论】:
标签: ios objective-c iphone xcode