簡體   English   中英

UIView animateWithDuration重新開始

[英]UIView animateWithDuration start over

我有一個簡單的問題:),但我想從Stackoverflow社區的優秀程序員中受益。

我在viewDidApp的源代碼視圖中使用UIView.animateWithDuration通過調用startTheStory()如下所示顯示動畫開始:

override func viewDidAppear(animated: Bool) {

    if !animate {

        startTheStory()
    }
}

然后,使用定制segue將視圖事務與目標視圖合並。

我的問題是事務在源視圖中重新啟動動畫時重新開始,因此我嘗試通過以下代碼停止動畫:

override func viewWillDisappear(animated: Bool) {
    animate = true

    self.view.layer.removeAllAnimations()
}

但這是行不通的。

我也嘗試在prepareForSegue()中,但是它不起作用。

任何想法?

謝謝

刪除此行self.view.layer.removeAllAnimations()

並添加這些行

[CATransaction begin]
[_backgroundView.layer removeAllAnimations]
[CATransaction commit]
[CATransaction flush]

記得導入QuartzCore/QuartzCore.h

您的動畫出演的原因是

if !animate {

        startTheStory()
    }

總是在viewDidAppear方法中執行,因為每次視圖將再次在屏幕上繪制時,“動畫”都設置為false。 當調用viewDidAppear時,將viewWillDisappear中的“動畫”設置為“真”將再次重置為“假”。 因此,嘗試在應用程序委托中保持“ animate” var全局,並設置該值即可。

暫無
暫無

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

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