gpt4 book ai didi

ios - 错误的 UIScrollView subview 放置

转载 作者:行者123 更新时间:2023-11-29 10:27:20 24 4
gpt4 key购买 nike

我正在以编程方式创建我的应用程序的用户界面,我已经被这个问题困扰了将近两天。

我有我的 MasterViewController,它创建了我的 ScrollView 的一个实例:

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 高度设置为它自己的高度,但在模拟器上执行后我仍然能够滚动。

其次,我设置了原点为 (0;0) 的 UIView“测试”,但它显示在我看来像 (0;self.frame.height/2) 的某些坐标处。

这是模拟器上的最终结果

enter image description here

有人有想法吗?非常感谢。

最佳答案

解决了!经过两天的挣扎,我终于得到了答案。UINavigationController 让 MainViewController 自动设置 UIScrollView 的 subview 插入,你只需要插入到我的 MasterViewController 的 init 方法中

self.automaticallyAdjustsScrollViewInsets = NO;

解决问题,让我的观点随心所欲。

关于ios - 错误的 UIScrollView subview 放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31492593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com