2016-09-30 167 views
8

不會播放自定義的segue動畫我遇到了一個不尋常的行爲,我卡住了一下,問題如下。第一次點擊按鈕

我使用BWWalkthrough庫以便將4張幻燈片作爲啓動屏幕。所以在我的appdelegate我有以下代碼初始化viewcontrollers:

let storyboard = UIStoryboard(name: "SlidesFlow", bundle: nil) 

let walkthrough = storyboard.instantiateViewController(withIdentifier: "SlidesView") as! BWWalkthroughViewController 
let page_zero = storyboard.instantiateViewController(withIdentifier: "page_1") 
let page_one = storyboard.instantiateViewController(withIdentifier: "page_2") 
let page_two = storyboard.instantiateViewController(withIdentifier: "page_3") 
let page_three = storyboard.instantiateViewController(withIdentifier: "page_4") 

walkthrough.delegate = self 
walkthrough.addViewController(page_zero) 
walkthrough.addViewController(page_one) 
walkthrough.addViewController(page_two) 
walkthrough.addViewController(page_three) 

一切都按預期工作,所以這裏沒有問題。在的viewController page_three我有一個按鈕使用自定義賽格瑞動畫

class sentSegueFromRight: UIStoryboardSegue { 

override func perform() 
{ 
    let src = self.source as UIViewController 
    let dst = self.destination as UIViewController 

    src.view.superview?.insertSubview(dst.view, aboveSubview: src.view) 
    dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0) 

    UIView.animate(withDuration: 0.25, 
           delay: 0.0, 
           options: UIViewAnimationOptions.curveEaseInOut, 
           animations: { 
           dst.view.transform = CGAffineTransform(translationX: 0, y: 0) 
     }, 
           completion: { finished in 
           src.present(dst, animated: false, completion: nil) 
     } 
    ) 
} 
} 

現在其重定向我到其他視圖控制器的問題是,如果我使用相同的代碼在一個普通視圖 - 控制按鈕和動畫作品,而不的問題。問題是當我使用BWWalkthrough的最後一張幻燈片中定義的segue時。我第一次按下應該出現的視圖控制器的按鈕確實會出現,但沒有相應的動畫。

上分離視圖控制器呈現視圖控制器是 氣餒

如果我使用的按鈕與標準的動畫:關閉它和錄音按鈕再次播放動畫,而是返回一個錯誤後(不使用我的自定義動畫代碼)我沒有錯誤,並播放默認動畫。

我似乎無法找到解決此問題的方法。有人偶然發現了這樣的事嗎?

回答

2

這裏的問題在於BWWalkthrough庫,它使用scrollview來呈現您添加的各種ViewController的所有視圖。

因此,您可以在滾動視圖的開頭(偏移屏幕寬度爲0)處添加dst.view,然後將其轉換爲偏移量(0,0)。

所有這些都是屏幕外的,因爲您目前處於漫遊的第三個屏幕(偏移量(屏幕寬度* 3,0))。因此,您不會看到動畫,並在segue結束時直接看到所呈現的視圖控制器。

要解決這個問題,請將segst中的dst.view添加到scrollview的超級視圖中。即代替src.view.superview?.insertSubview(dst.view, aboveSubview: src.view) 在編輯中寫入src.view.superview?.superview?.insertSubview(dst.view, aboveSubview: src.view)。 (假設你只在漫遊中使用segue)

如果你打算在其他地方也使用segue,那麼你可以在segue中添加一個類型檢查來檢查src.view的superview是一個滾動視圖,如果是,則將dst.view添加到滾動視圖的超級視圖。

+0

謝謝你爲我指出這一點。這說得通。 – Netra

相關問題