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/

相关文章:

ios - 以更简洁的方式在 Swift 中访问 JSON Key

ios - 带有文本框的 Storyboard ScrollView

iphone - NSString 形式的 HTML 电子邮件模板

iphone - 在 iPhone 上提取 UISegmentedControl 的图像

ios - 枚举字符串值 - 二元运算符不能应用于 Bool 和 String 类型的操作数

ios - 为什么我放置在 ScrollView 中的 ImageView 具有扭曲的高度?

IOS, swift : How come my subclass of UIScrollView doesn't scroll?

iphone - 使用 nsdata 在 <img> 标签中显示图像

iphone - 如何重构 iPhone 应用程序以在 iPad 上本地运行

ios - 如果没有收到数据则抛出异常