相关疑难解决方法(0)

调用topLayoutGuide完全打破滚动?

我对这个topLayoutGuide方法有一些奇怪的问题,我必须在setAutomaticallyAdjustsScrollViewInsets:不起作用的情况下使用它.为了缩小问题的原因,我创建了以下最小的示例,它只是为测试设置了一个基本的表视图:

  1. 在Xcode中设置一个新的iOS Single View应用程序.
  2. 在ViewController.m的实现中粘贴以下代码:

    @implementation ViewController
    
    - (void)loadView
    {
        [self setTableView:[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]];
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self setAutomaticallyAdjustsScrollViewInsets:NO]; // [*]
    }
    
    - (void)viewDidLayoutSubviews
    {
        UITableView *tableView = [self tableView];
    
        UIEdgeInsets insets = [tableView contentInset];
        // insets.top = [[self topLayoutGuide] length]; // [1]
        // insets.top = 100;                            // [2]
    
        [tableView setContentInset:insets];
        [tableView setScrollIndicatorInsets:insets];
    }
    
    #pragma mark - Table view data source
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 100;
    }
    
    - (UITableViewCell *)tableView:(UITableView …
    Run Code Online (Sandbox Code Playgroud)

objective-c uiviewcontroller ios ios7

14
推荐指数
1
解决办法
1024
查看次数

标签 统计

ios ×1

ios7 ×1

objective-c ×1

uiviewcontroller ×1