7
我想在2014年的WWDC的會話214中製作一個彈出窗口。iOS 8:在緊湊模式下將具有模糊效果的UIVisualEffectView應用於模態PopOver
於是我開始建設使用具有被「存在酥料餅」賽格瑞連接兩種觀點的IB我的應用程序,因爲這樣的:
的酥料餅視圖包含填充它的父文本視圖,具有以下限制:
爲了支持該模式酥料餅下面的代碼:
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .OverFullScreen
}
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
let navigationController = UINavigationController(rootViewController: controller.presentedViewController)
controller.presentedViewController.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "done"), animated: true)
return navigationController
}
這給了我下面再sult:
然後我嘗試添加帶有模糊效果的UIVisualEffectView。起初,我只是簡單地將子視圖添加到呈現的控制器視圖中,在檢查視圖層次結構後,我意識到我的效果視圖實際上位於我的文本視圖之上,但我的文本視圖卻正確放置。於是,我嘗試了insertSubview:atIndex:方法就像這樣:
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView
effectView.setTranslatesAutoresizingMaskIntoConstraints(false)
controller.presentedViewController.view.insertSubview(effectView, atIndex: 0)
let viewList : [String : UIView] = ["effectView" : effectView]
let navigationController = UINavigationController(rootViewController: controller.presentedViewController)
controller.presentedViewController.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "done"), animated: true)
controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[effectView]|", options: nil, metrics: nil, views: viewList))
controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[effectView]|", options: nil, metrics: nil, views: viewList))
return navigationController
}
但我仍然無法出現在IB定義的文本視圖:
通過視圖層次,我可以看到我的文字不知何故,當我將UIVisualEffectView插入索引0時,它會移動到導航條的下方。
有關如何以編程方式在我的文本下方設置模糊效果而不使其消失/移動到導航欄下方的任何想法?
乾杯