簡體   English   中英

快速animateWithDuration動畫不正確

[英]swift animateWithDuration animation not right

我隱藏了導航欄和下面的UIView,當我滾動頁面時,它充當了它的擴展欄

我的應用程序的構建方式如下:

VC包含具有嵌入式表視圖的容器視圖。

從表視圖中,我可以看到一個委托,一旦用戶向上或向下滾動,它們就會通知VC1。

我現在的問題是動畫看起來不那么好。 我想做的是為擴展欄設置動畫,以同時使用淡入或淡出效果對動畫進行上下動畫處理。 發生這種情況時,我還將更新容器視圖上的頂部約束,以便表視圖將填充整個屏幕。 (我不確定是否正確使用layoutneeded()或在更新約束時是否應使用其他方法)

我的代碼:

func ContainerTableViewControllerScrolledUp(controller: ContainerTableViewController) {
        self.navigationController?.setNavigationBarHidden(false, animated: true)
        println("UP")
        UIView.animateWithDuration(
            1.5,
            delay: 0,
            usingSpringWithDamping: 0.7,
            initialSpringVelocity: 0.5,
            options: nil,
            animations: {
                self.extensionV.alpha = 1
                self.tableVConst.constant = 0
            },  completion: { finished in
                self.view.layoutIfNeeded()
            }
        )
    }

func ContainerTableViewControllerScrolledDown(controller:ContainerTableViewController) {
    self.navigationController?.setNavigationBarHidden(true, animated: true)
    println("DOWN")
    UIView.animateWithDuration(
        1.5,
        delay: 0,
        usingSpringWithDamping: 0.7,
        initialSpringVelocity: 0.5,
        options: nil,
        animations: {
            self.extensionV.frame.origin.y = CGFloat(-10)
            self.tableVConst.constant = -41
            self.extensionV.alpha = 0
        }, completion: { finished in
            self.view.layoutIfNeeded()
        }
    )
}

extensionV是擴展視圖tableVConst是保存我的表視圖的容器視圖的最高約束

那么,如何編輯代碼以使擴展視圖具有淡入/淡出效果來向上/向下動畫?

與其在完成塊中調用self.view.layoutIfNeeded()self.view.layoutIfNeeded()在返回之前在最后一行的動畫塊內調用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM