尝试滑动一个单元格,另一个 View 就会出现。到目前为止,这是我的代码,但我看不到 rightView。相反,它限制了我看到 leftView(我想要相反的......leftView 甚至不存在)。对 CGRects 和 CGRectOffsets 很困惑。如果您能更正我的代码,那就太好了。谢谢。
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = self.bounds;
self.scrollView.frame = frame;
self.scrollView.contentSize = CGSizeMake(frame.size.width*2, frame.size.height);
self.centerView.frame = CGRectOffset(frame, frame.size.width, 0);
self.rightView.frame = CGRectOffset(frame, frame.size.width*2, 0);
[self.scrollView scrollRectToVisible:self.centerView.frame animated:NO];
[self.scrollView setUserInteractionEnabled:YES];
self.scrollView.scrollEnabled = YES;
}
最佳答案
您将 centerView 和 rightView 的偏移分别设置为 frame.size.width
和 frame.size.width*2
。您希望中心为 0
,右 View 为 frame.size.width
。
您只是将 View 移得太多,所以左边的 frame.size.width
像素数没有 View 。
关于iphone - CGRectOffset 导致滑动方向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18140238/