Ios 更新内容时,UIScrollView帧y坐标上升20像素

Ios 更新内容时,UIScrollView帧y坐标上升20像素,ios,swift,uiscrollview,Ios,Swift,Uiscrollview,原始视图,在顶部位置: 添加新内容后的视图,在顶部位置(视图向上移动了20个像素) 额外滚动一点到顶部后查看(如刷新时向下拖动内容) 因此,当我在这个视图中添加一个新视图并更新大小和所有内容以使其看起来正确时,我仍然有一个无法解决的问题。这使得滚动视图从y轴法线点上方20个像素开始 我试图通过在scrollView框架中添加+20像素来解决这个问题。当我只进行一次更新时,它工作正常,如果我现在进行几次更新,scrollView将在实际应该开始的位置下方的许多像素处开始。我尝试过锁定+20加

原始视图,在顶部位置:

添加新内容后的视图,在顶部位置(视图向上移动了20个像素)

额外滚动一点到顶部后查看(如刷新时向下拖动内容)

因此,当我在这个视图中添加一个新视图并更新大小和所有内容以使其看起来正确时,我仍然有一个无法解决的问题。这使得滚动视图从y轴法线点上方20个像素开始

我试图通过在scrollView框架中添加+20像素来解决这个问题。当我只进行一次更新时,它工作正常,如果我现在进行几次更新,scrollView将在实际应该开始的位置下方的许多像素处开始。我尝试过锁定+20加法,使其仅在第一次发生,但没有成功。另外,滚动视图在新视图中也会完全混乱

我没有故事板或xib。该项目完全是以编程方式开发的

顺便说一句,我检查了scollView、self.view和cardView中的每个变量,我认为这些变量会影响这一点。问题是它们的帧变量都没有任何变化。但他们的行为好像发生了变化,我就是想不出是什么

override func viewDidLoad() {
    super.viewDidLoad()

    self.automaticallyAdjustsScrollViewInsets = false

    navigationController?.navigationBar.hidden = false

    createScrollView()
}
//如何在viewdidload中创建SV

func createScrollView() {
    scrollView.frame = self.view.frame
    scrollView.showsVerticalScrollIndicator = true
    scrollView.scrollEnabled = true
    scrollView.userInteractionEnabled = true
    scrollView.delegate = self
    scrollView.sizeToFit()
    scrollView.contentSize = CGSize(width: cardWidth, height: 100)
    view.addSubview(scrollView)
}
//如何在scrollview中创建视图

func makeNewCard() {
    var newCard = CardView()
    newCard.createCard(sender: self)

    gestureRecognizer = UIPanGestureRecognizer(target: self, action: Selector("cardWasDragged:"))
    gestureRecognizer.delegate = self
    newCard.addGestureRecognizer(gestureRecognizer)

    scrollView.contentSize = CGSize(width: cardWidth, height: newCard.frame.height + CGFloat(50 + 64))
    scrollView.addSubview(currentCardView)
}
//在另一个视图类中创建我的视图

func createCard(#sender: CardVC) {
    frame = CGRect(x: ScreenWidth/15, y: 64, width: cardWidth, height: cardHeight)
    contentMode = UIViewContentMode.ScaleAspectFit
    userInteractionEnabled = true
}
//在视图中添加约20-50像素的新内容

func newContent() {
    var extraHeight = newHeight

    frame = CGRect(x: ScreenWidth/15, y: 64, width: cardWidth, height: frame.height + extraHeight)

    senderView.scrollView.contentSize = CGSize(width: cardWidth, height: senderView.scrollView.contentSize.height + extraHeight - 20) //Had to put -20, I guess I will remove the -20 after this is fixed     
}

可能是因为ViewController属性(在顶部栏下)的缘故,我也遇到了同样的问题

编码

    self.extendedLayoutIncludesOpaqueBars = NO;
尝试将其更改为:

请重播,如果它工作?如果不是的话,我会试着去想一些其他的原因。
祝您好运

automaticallyAdjustsScrollViewInsets=false在视图中控制器准备好了,编辑问题我不使用故事板,因此我没有此UI。但是我有一个代码块:self.automaticallyAdjustsScrollViewInsets=false我没有笔尖,所以不知道该怎么做。添加到viewdidload中,但不起作用。我不认为我和巴萨有什么问题,我也不这么认为,但我也有同样的问题,这条线解决了。。不管怎么说,我在想是什么原因造成的,如果我想点什么,我会回答的。。。