本文介绍了UIScrollView -setContentInset 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的滚动视图设置,我想去掉 contentInset.

I've got a fairly straightforward scroll view setup, and I want to get rid of the contentInset.

MyViewController.h

MyViewController.h

@interface MyViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end

MyViewController.m

MyViewController.m

@interface MyViewController

-(void)viewDidLoad
{
    [super viewDidLoad];

    [self.scrollView setContentInset:UIEdgeInsetsZero];
    ...
}

在我的故事板中,我的滚动视图从导航栏的底部开始.不幸的是,我在运行应用程序时得到以下结果.似乎 contentInset 仍然非常活跃.我已将 scrollView 背景设为绿色.

In my storyboard, my scrollview starts from the bottom of the navbar. Unfortunately, I get the below result when running the app. Seems like the contentInset is still very much alive. I've made the scrollView background green.

只提供故事板的图片和出口链接

just providing a pic of the storyboard and the outlet link

推荐答案

好的,代码如下

[self.myScrollViewOutlet setContentInset:UIEdgeInsetsZero];

仅在放置在 -(void)viewWillLayoutSubviews 中时有效.

它在 -(void)viewDidLoad-(void)viewWillAppear:(BOOL)animated- 中不起作用(void)viewDidAppear:(BOOL)animated.

It did not work in -(void)viewDidLoad, -(void)viewWillAppear:(BOOL)animated or -(void)viewDidAppear:(BOOL)animated.

希望对未来的人有所帮助!

Hope that helps people in future!

这篇关于UIScrollView -setContentInset 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:27