Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用自定义转换管理器展开时出现的问题_Swift_Ios8 - Fatal编程技术网

Swift 使用自定义转换管理器展开时出现的问题

Swift 使用自定义转换管理器展开时出现的问题,swift,ios8,Swift,Ios8,我构建了一个自定义的过渡管理器,用于处理在我的应用程序中空间移动的视图 我有三个视图控制器:MainViewController、PastSessionViewController和JournalViewController 我的问题是:当用户从主会话转到过去的会话再转到日志,并按Done in Journal返回主会话时,视图立即跳转到过去的会话,然后主会话从右侧放大 预期的行为是将Main从屏幕左侧推入,将Journal从屏幕右侧推出 我在animationControllerForDism

我构建了一个自定义的过渡管理器,用于处理在我的应用程序中空间移动的视图

我有三个视图控制器:MainViewController、PastSessionViewController和JournalViewController

我的问题是:当用户从主会话转到过去的会话再转到日志,并按Done in Journal返回主会话时,视图立即跳转到过去的会话,然后主会话从右侧放大

预期的行为是将Main从屏幕左侧推入,将Journal从屏幕右侧推出

我在animationControllerForDismissedController中添加了一个换行符,并注意到discomered.description是PastSessionViewController,当它应该是JournalViewController时,在按“完成”后从Journal移动到Main时

我不知道这是为什么。我已正确连接了展开段,并且JournalViewController中prepareForSegue中的代码有意义。我不认为我需要定义dismissing视图控制器,这应该像在其他转换中一样为我处理

如果有人对如何解决这个问题有任何想法,以便在过渡之前,过去的会话不会跳回用户的视图中,那将非常感谢

谢谢

TransitionManager.swift:

日志视图控制器:


传统的观点似乎是,不能使用UIViewControllerAnimatedTransitioning来进行展开分段。看到了吗?我玩了一会儿,看到了你描述的相同行为。我唯一成功的解决方法是在prepareForSegue中拍摄视图的快照,然后将animateTransition更改为隐藏视图;b使用快照图像添加图像视图;c设置此图像视图的动画;完成后,删除图像视图和快照。非常难看。使用animateTransition肯定有更好的方法来实现这一点!
import UIKit

class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning , UIViewControllerTransitioningDelegate {
    var presenting = true
    var direction = "down" //from the top. accepts up/down/left/right

    // transition between pressing "Begin" and the water beginning to fill
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
        return 0.8
    }

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        let container = transitionContext.containerView()
        let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
        let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!

        var offScreenTop: CGAffineTransform
        var offScreenBottom: CGAffineTransform

        switch self.direction {
        case "up" :
            offScreenTop = CGAffineTransformMakeTranslation(0, container.frame.height)
            offScreenBottom = CGAffineTransformMakeTranslation(0, -container.frame.height)

            toView.transform = self.presenting ? offScreenTop : offScreenBottom

            container.addSubview(fromView)
            container.addSubview(toView)
        case "left" :
            // TODO: rename top/bottom/l/r
            offScreenTop = CGAffineTransformMakeTranslation(-container.frame.width, 0)
            offScreenBottom = CGAffineTransformMakeTranslation(container.frame.width, 0)

            toView.transform = self.presenting ? offScreenTop : offScreenBottom

            container.addSubview(fromView)
            container.addSubview(toView)
        case "right" :
            offScreenTop = CGAffineTransformMakeTranslation(container.frame.width, 0)
            offScreenBottom = CGAffineTransformMakeTranslation(-container.frame.width, 0)

            toView.transform = self.presenting ? offScreenTop : offScreenBottom

            container.addSubview(fromView)
            container.addSubview(toView)
        default:
            // down
            offScreenTop = CGAffineTransformMakeTranslation(0, -container.frame.height)
            offScreenBottom = CGAffineTransformMakeTranslation(0, container.frame.height)

            toView.transform = self.presenting ? offScreenTop : offScreenBottom

            container.addSubview(toView)
            container.addSubview(fromView)
        }

        let duration = self.transitionDuration(transitionContext)

        UIView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
                fromView.transform = self.presenting ? offScreenBottom : offScreenTop
                toView.transform = CGAffineTransformIdentity
            }, completion: {
                finished in transitionContext.completeTransition(true)
        })
    }

    // return the animator when presenting a viewcontroller
    // rememeber that an animator (or animation controller) is any object that adheres to the UIViewControllerAnimatedTransitioning protocol
    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        self.presenting = true

        return self
    }

    // return the animator used when dismissing from a viewcontroller
    func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        self.presenting = false

        return self
    }
}
import UIKit
import CoreData

class JournalViewController: UIViewController, UITextViewDelegate {    
    let transitionManager = TransitionManager()

    var journalEntryCoreDataLocation: Int?
    var journalEntryToEdit: String?
    var journalEntryToEditTimestamp: NSDate?

    @IBOutlet weak var journalEntryLabel: UILabel!
    @IBOutlet weak var journalEntryTextArea: UITextView!

    @IBAction func doneJournalEntry(sender: AnyObject) {
        journalEntryTextArea.resignFirstResponder()

        // do some stuff in coredata
    }

    @IBAction func cancelButtonPressed(sender: AnyObject) {
        journalEntryTextArea.resignFirstResponder()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
    }

    override func viewWillAppear(animated: Bool) {
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        let destinationVC = segue.destinationViewController as ViewController
        destinationVC.showJournalButton = false

        let transitionManager = self.transitionManager
        transitionManager.presenting = true
        transitionManager.direction = "left"
//        transitionManager.animationControllerForDismissedController(JournalViewController)

        destinationVC.transitioningDelegate = transitionManager
    }
}