UIScrollView自动滚动64点

 手机用户2602934963 发布于 2023-02-12 16:11

我正在添加UIScrollView一个UIViewControllers view.由于某种原因,在将滚动视图添加到视图并显示之间,将contentOffset设置为{0, -64},64是状态栏的20加上导航栏的44点(我猜).下面是一些重现问题的代码和图像.

如何阻止iOS设置contentOffset


- (void)viewDidLoad
{
    [super viewDidLoad];

    _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 100, 100, 100)];
    _scroll.backgroundColor = [UIColor greenColor];
    _scroll.delegate = self;

    UIView *red = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
    red.backgroundColor = [UIColor redColor];
    [_scroll addSubview:red];

    [self.view addSubview:_scroll];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // outputs {0, -64}
    NSLog(@"%@", NSStringFromCGPoint(_scroll.contentOffset));
}

截图

1 个回答
  • 设置automaticallyAdjustsScrollViewInsets您的视图控制器上NO,否则它会在它的第一子视图调整插图这么恰巧是根视图UIScrollView类.

    有关iOS 7 Transition Guide的更多信息.

    2023-02-12 16:13 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有