【发布时间】:2014-02-03 11:25:52
【问题描述】:
我在 IB 中设置了一个 UIScrollView,其自动布局包含一个 UIImageView。您可以查看 Evgenii 的 Github 存储库,了解它是如何设置的:https://github.com/evgenyneu/ios-imagescroll
滚动视图用于启用捏拉缩放。我希望能够使用新的UIAttachmentBehavior 使用UIPanGestureRecognizer 移动滚动视图。这在没有自动布局的情况下效果很好,但启用自动布局后,滚动视图内容会闪烁并且滚动视图会失真。
- (void)handlePanGesture:(id)sender
{
CGPoint p = [_panGesture locationInView:self.view];
if (_panGesture.state == UIGestureRecognizerStateBegan) {
self.scrollView.userInteractionEnabled = NO;
CGPoint center = self.view.center;
UIOffset offset = UIOffsetMake(p.x - center.x, p.y - center.y);
_attachBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.scrollView offsetFromCenter:offset attachedToAnchor:p];
[_animator addBehavior:_attachBehavior];
} else if (_panGesture.state == UIGestureRecognizerStateChanged) {
_attachBehavior.anchorPoint = p;
}
}
我的猜测是设置为滚动和图像视图的约束会干扰附件行为,滚动视图的contentSize 也取决于其内容和约束。
任何想法如何得到这个工作将不胜感激。
编辑:使用普通视图而不是 scrollView/imageView 组合进行测试,并且存在相同的问题。因此,使用UIAttachmentBehavior 进行自动布局的平移目的肯定是个问题。
【问题讨论】:
-
您可以一起使用它们(例如github.com/whilethis/UIKit-Dynamics-101),但不确定
UIAttachmentBehavior。 -
是的,没有附件,我之前遇到过这个问题。
标签: ios uiscrollview autolayout uikit-dynamics