UIScrollview总是在IOS目标C中弹回顶部

时间:2018-10-19 06:47:45

标签: ios objective-c uiscrollview

我有一个滚动视图,当我滚动到底部时,它始终会跳到顶部。我尝试了多种方法来解决此问题。我知道有人问过同样的问题,但没有一个对我有帮助。 这些是我使用的代码

[self.nfaSscrollview setContentOffset:CGPointMake(0,3185)];

[self.NFASscrollview setContentSize:CGSizeMake(self.NFASscrollview.frame.size.width,3185)];

这是我在 viewDidLoad

中写的
- (void)viewDidLoad {

    [super viewDidLoad];

    [self.NFASscrollview setContentSize:CGSizeMake(self.NFASscrollview.frame.size.width,3185)];
    _NFASscrollview.scrollEnabled=YES;

    _View3.hidden=YES;

    self.view1HeightConstraint.constant = 0.0;
    [self.view layoutIfNeeded];

3185只是Scroll视图中最后一个内容的(Y的高度+起点)。

This is the screenshot of my Layout

This is the screenshot of my Layout

视图约束的屏幕截图

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

我认为我的约束可能存在一些问题。我不知道如何解决这个问题。

2 个答案:

答案 0 :(得分:0)

在获得 NFASscrollview 的框架之前,请尝试使用[self.view layoutIfNeeded]。因为这样可以从自动版式的约束条件中获得 NFASscrollview 的当前准确帧。

答案 1 :(得分:0)

超级视图滚动视图约束中检查负值,并将其设置为 0 。甚至我也遇到过同样的问题,我通过将 Super View 底部空间约束设置为 0 来解决此问题。