Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Ios 为现有视图添加活力_Ios_Swift_Xcode6 - Fatal编程技术网

Ios 为现有视图添加活力

Ios 为现有视图添加活力,ios,swift,xcode6,Ios,Swift,Xcode6,我对斯威夫特很陌生,目前正试图实现一个模糊和充满活力的效果模式 let modalViewController = FavoritesViewController() modalViewController.modalPresentationStyle = .OverFullScreen self.presentViewController(modalViewController, animated: true, completion: nil) 这就是我创建模态视图控制器的方式,它随后执行以

我对斯威夫特很陌生,目前正试图实现一个模糊和充满活力的效果模式

let modalViewController = FavoritesViewController()
modalViewController.modalPresentationStyle = .OverFullScreen
self.presentViewController(modalViewController, animated: true, completion: nil)
这就是我创建模态视图控制器的方式,它随后执行以下
viewDidLoad()
方法:

override func viewDidLoad() {
    super.viewDidLoad()

    // Instantiate a view from the FavoritesView.xib and add
    // it to this Controller's view
    let optionsView = UINib(nibName: "FavoritesView", bundle: nil).instantiateWithOwner(self, options: nil)[0] as UIView
    view.addSubview(optionsView)

    // Create a UIVisualEffectView with a blur effect and
    // insert it to this Controller's view
    let blurEffect = UIBlurEffect(style: .Dark)
    let blurView = UIVisualEffectView(effect: blurEffect)
    blurView.frame = self.view.bounds
    blurView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
    blurView.setTranslatesAutoresizingMaskIntoConstraints(true)
    view.insertSubview(blurView, atIndex: 0)

    // Create a UIVisualEffectView with a vibrancy effect
    let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(forBlurEffect: blurEffect))
    vibrancyView.setTranslatesAutoresizingMaskIntoConstraints(false)

    vibrancyView.contentView.addSubview(optionsView) 
    // This is the part I'm unsure of.

    blurView.contentView.addSubview(vibrancyView)
}
用这段代码可以创建并显示模糊,但活力似乎不起作用。据我所知,首先将
选项视图
(包含标签和按钮的模式视图)添加到控制器的视图中,然后在其后面插入模糊

最后创建Vibrance视图,
选项视图
添加到Vibrance视图的
内容视图
(我认为这是必要的,以便Vibrance效果可以应用到视图标签等)。然后,该振动视图将添加到模糊视图中


然而,标签和按钮仍然不会在应用振动效果时显示。我是否需要对
.xib
-文件中的UI元素进行任何调整以应用振动,还是应该自动应用振动?还是我遗漏了什么?

您好,请在
视图上尝试一下,它将出现


viewDidLoad
不是屏幕上元素的正确位置(
UIView
等等)

它仍然不应用振动效果。视图在
viewDidLoad
中也不存在,因为它是通过UINib实例化whowner从附加的.xib加载的。行
vibrancyView.contentView.addSubview(optionView)
将其终止。如果没有它,视图将以模糊的背景显示(就像预期的那样),但是使用它,将根本不显示任何内容。