Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 UIVisualEffectView在显示新视图时创建不需要的阴影_Swift_Uiviewcontroller_Shadow_Blur - Fatal编程技术网

Swift UIVisualEffectView在显示新视图时创建不需要的阴影

Swift UIVisualEffectView在显示新视图时创建不需要的阴影,swift,uiviewcontroller,shadow,blur,Swift,Uiviewcontroller,Shadow,Blur,在我的自定义演示转换中,我创建了一个新的视图控制器,它将预先显示在当前活动视图控制器的顶部(请参见屏幕截图)。不知怎的,蓝色视图控制器后面有一个阴影,我不知道它来自哪里。有没有办法阻止阴影的出现 项目完全为空,并且只有两个空视图控制器 这是我正在使用的代码: class ViewController: UIViewController { let transitionDelegate = TransitionManager() override func viewDidLoa

在我的自定义演示转换中,我创建了一个新的视图控制器,它将预先显示在当前活动视图控制器的顶部(请参见屏幕截图)。不知怎的,蓝色视图控制器后面有一个阴影,我不知道它来自哪里。有没有办法阻止阴影的出现

项目完全为空,并且只有两个空视图控制器

这是我正在使用的代码:

class ViewController: UIViewController {

    let transitionDelegate = TransitionManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .yellowColor()

        let button = UIButton(type: .System)
        button.frame = CGRectMake(10, 10, 50, 50)
        button.addTarget(self, action: "test:", forControlEvents: .TouchUpInside)
        button.backgroundColor = UIColor.redColor()

        view.addSubview(button)
    }

    func test(sender: UIButton) {
        let destination = UIViewController()
        destination.view.backgroundColor = .blueColor()

        destination.transitioningDelegate = transitionDelegate
        destination.modalPresentationStyle = .Custom
        presentViewController(destination, animated: true, completion: nil)
    }
}
用于显示视图的代码:

class PresentingTransition: NSObject, UIViewControllerAnimatedTransitioning {

    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return 0.3
    }

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        let presented = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
        let container = transitionContext.containerView()!
        let durations = transitionDuration(transitionContext)

        presented.view.alpha = 0

        container.addSubview(presented.view)

        UIView.animateWithDuration(durations, animations: { presented.view.alpha = 1 }) { transitionContext.completeTransition($0) }
    }
}
用于处理显示视图控制器的代码:

class PresentationController: UIPresentationController {

    var background: UIView!

    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)

        prepareBackground()
    }

    func prepareBackground() {
        self.background = UIView(frame: presentingViewController.view.bounds)

        let blur = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
        blur.frame = background.bounds
        blur.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]

        background.addSubview(blur)

        let tapRecognizer = UITapGestureRecognizer(target: self, action: "backgroundTapped:")
        background.addGestureRecognizer(tapRecognizer)
    }

    func backgroundTapped(tapRecognizer: UITapGestureRecognizer) {
        presentingViewController.dismissViewControllerAnimated(true, completion: nil)
    }

    override func presentationTransitionWillBegin() {
        let container = containerView!

        background.frame = container.bounds
        background.alpha = 0.0

        container.insertSubview(background, atIndex: 0)

        presentedViewController.transitionCoordinator()?.animateAlongsideTransition({ _ in self.background.alpha = 1.0 }, completion: nil)
    }

    override func dismissalTransitionWillBegin() {
        presentedViewController.transitionCoordinator()?.animateAlongsideTransition({ _ in self.background.alpha = 0.0 }, completion: nil)
    }

    override func frameOfPresentedViewInContainerView() -> CGRect {
        return containerView!.bounds.insetBy(dx: 100, dy: 100)
    }

    override func containerViewWillLayoutSubviews() {
        background.frame = containerView!.bounds
        presentedView()!.frame = frameOfPresentedViewInContainerView()
    }
}