Swift / CollectionView随着Custom Segue随机消失

时间:2016-03-05 13:22:22

标签: ios swift uicollectionview

UICollectionView上有一个UIView。使用自定义segue调用屏幕:

    import UIKit

class CustomUIStoryBoardSegue: UIStoryboardSegue {

    override func perform() {

        let firstVC = self.sourceViewController.view as UIView!
        let secondVC = self.destinationViewController.view as UIView!

        let screenWidth = UIScreen.mainScreen().bounds.size.width
        let screenHeight = UIScreen.mainScreen().bounds.size.height


        secondVC.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight)

        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondVC, aboveSubview: firstVC)

        // Animate the transition.
        UIView.animateWithDuration(0.3, animations: { () -> Void in // set animation duration

            firstVC.frame = CGRectOffset(firstVC.frame, 0.0, 0.0) // old screen stay

            secondVC.frame = CGRectOffset(secondVC.frame, -screenWidth, 0.0) // new screen strave from right to left

            }) { (Finished) -> Void in
                self.sourceViewController.presentViewController(self.destinationViewController as UIViewController,
                    animated: false,
                    completion: nil)
        }
    }

}

屏幕由菜单上的按钮调用。如果我连续10到20次调用此屏幕,则{10}错过了UICollectionView。如果我禁用自定义segue,一切都很好,UICollectionView一直存在。

我错过了什么或者这个segue有什么问题?

0 个答案:

没有答案