iphone - CGRectOffset 导致滑动方向错误

标签 iphone ios uiscrollview frame cgrect

尝试滑动一个单元格,另一个 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.widthframe.size.width*2。您希望中心为 0,右 View 为 frame.size.width

您只是将 View 移得太多,所以左边的 frame.size.width 像素数没有 View 。

关于iphone - CGRectOffset 导致滑动方向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18140238/

相关文章:

iphone - 当用户点击“编辑”按钮时重做 UITableView 布局?

iPhone - 关闭多个 ViewController

iphone - UILongPressGestureRecognizer 关闭 UIButton 高亮显示

ios - ios/mac 开发者的 iCloud 替代品

ios - UIScrollView 缩放不会产生滑动

ios - 将 UIScrollView 滚动到被键盘隐藏的 UITextView 的奇怪行为

iphone - 使用 OCMock 测试 NSWidowController

iphone - 在 XCode 4 中调用 segue 的正确方法是什么?

ios - 如何在 iOS 6 中以编程方式更改设备方向

ios - 嵌套的 UIScrollView 防止弹跳冒泡并允许在列表末尾进行父分页