【发布时间】:2015-10-08 03:57:12
【问题描述】:
我正在以编程方式创建我的应用程序的 UI,我已经被这个问题困扰了将近两天了。
我的 MasterViewController 创建了我的滚动视图的一个实例:
CGRect bottomViewFrame = CGRectMake(0,self.view.bounds.size.height-self.view.bounds.size.height/4.6,self.view.frame.size.width,100);
BottomView *bottomView = [[BottomView alloc] initWithFrame:bottomViewFrame];
在我的 ScrollView 的 initWithFrame: 方法中,我有:
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
self.backgroundColor = [UIColor blackColor];
self.contentSize = CGSizeMake(self.bounds.size.width, self.bounds.size.height);
self.showsVerticalScrollIndicator = NO;
self.pagingEnabled = YES;
UIView* test = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
test.backgroundColor = [UIColor redColor];
[self addSubview:test];
return self;
}
有一些行为不正确... 首先,如您所见,我将 ScrollView 的 contentSize 高度设置为它自己的高度,但在模拟器上执行后我仍然能够滚动。
其次,我将 UIView“测试”设置为原点为 (0;0),但它显示的坐标在我看来像 (0;self.frame.height/2)。
这是模拟器上的最终结果
有人知道吗?提前感谢,非常感谢。
【问题讨论】:
-
我尝试重构整个代码并删除随机内容以了解导致错误的原因。我最终为主窗口 rootViewController 提供了 MasterViewController,而不是之前的 UINavigationController 实例。似乎滚动视图现在遵循预期的行为但是......什么? UINavigationController 如何影响 UIScrollView?如何同时使用两者?
标签: ios objective-c iphone uiview uiscrollview