简体   繁体   English

呈现具有透明背景且从左到右过渡的新视图控制器时出现问题

[英]Issue while presenting New View controller having Transparent Background with Transition from Left to right

I am trying to present a new view controller from Left Side with Transition.我正在尝试从带有过渡的左侧呈现一个新的视图控制器。 Here is the Code.这是代码。

 @IBAction func presentNewVC(_ sender: Any) {

        let storyBoard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let leftMenuController:NewViewController = storyBoard.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController

        leftMenuController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext

        leftMenuController.providesPresentationContextTransitionStyle = true
        leftMenuController.definesPresentationContext = false

        let transition = CATransition()
        transition.duration = 1.0
        transition.type = kCATransitionMoveIn
        transition.subtype = kCATransitionFromLeft

        transition.fillMode = kCAFillModeRemoved

        view.window!.layer.add(transition, forKey: kCATransition)
        present(leftMenuController, animated: false, completion: nil)

    }

Now while sliding Animation is being performed while transition the existing view in background also appears to be sliding.现在,当正在执行滑动动画时,背景中的现有视图也似乎在滑动。

Ideally the transparent new view controller should appear to move from left to right but it also shows existing view as it's background while moving.理想情况下,透明的新视图控制器应该看起来从左向右移动,但它也会在移动时将现有视图显示为背景。

Edit: Just to bring more clarity: It's not How to Navigate from Left to Right I am looking for.编辑:只是为了更清晰:这不是我正在寻找的如何从左到右导航。 The Transition is achieved & working fine.过渡已实现且工作正常。 The Issue is different.问题是不同的。 As my Left Menu View is transparent, while presenting it from left to right it also shows underlying existing view as it's own background while transition.由于我的左菜单视图是透明的,在从左到右呈现时,它还显示了底层现有视图,因为它在过渡时是自己的背景。 Please refer the screenshots & Video.请参考截图和视频。 Just want to stop this while transition.只是想在过渡时停止这个。 Only left transparent view being presented should move from left to right.只有呈现的左透明视图应该从左向右移动。 Please refer Video & Screenshot for more details.有关详细信息,请参阅视频和屏幕截图。

Click here to watch video to understand the issue单击此处观看视频以了解问题

While Animation: (Problem)虽然动画:(问题) 在此处输入图片说明

At the End: (As expected)最后:(如预期) 在此处输入图片说明

Here is something I've been using for left to right transition, is this what you are looking for?这是我一直用于从左到右过渡的东西,这是您要找的吗?

class SegueFromLeft: UIStoryboardSegue {
override func perform()
{
    let src = self.source
    let dst = self.destination

    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)
    }
    )
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM