2017-07-13 1 views
2

サブパネルを表示したい、これはtransperrentなので、メインビューコントローラーをぼかす。これはうまくいきますが、メインビューコントローラに戻ったときに、ブレが残ります。ビューが表示されたか、popoverPresentationControllerDidDismissPopoverのようにメインビューのどのセクションにも移動しません。メインビューに戻るときにスウィフトブラー効果が解除されない

私はぼかしを作成し、サブビューを表示するには、このコードを実行します。サブビューを終了すると

if !UIAccessibilityIsReduceTransparencyEnabled() { 
    self.view.backgroundColor = UIColor.clear 

    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) 
    let blurEffectView = UIVisualEffectView(effect: blurEffect) 
    blurEffectView.frame = self.view.bounds 
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

    self.view.addSubview(blurEffectView) 
} 

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PriceAlarmPopUp") as! PriceAlarmPopupViewController 
self.addChildViewController(popOverVC) 
popOverVC.view.frame = self.view.frame 
self.view.addSubview(popOverVC.view) 

popOverVC.didMove(toParentViewController: self) 

、私が行います

self.view.removeFromSuperview() 

は私が間違って行うものがありますか?私はすでにいくつかのソリューションを試しましたが、ぼかしサブビューを取り除くことはできませんでした。

+0

を望むなら、それもアニメーション可能だ、self.view blurEffectView.removeFromSuperview() –

答えて

1

でblurEffectViewビューを削除するビューにタグを追加します。

class MyVC: UIViewController { 

    private weak var blurView: UIView? 

    func foo() { 
     if !UIAccessibilityIsReduceTransparencyEnabled() { 
      self.view.backgroundColor = UIColor.clear 
      let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) 
      let blurEffectView = UIVisualEffectView(effect: blurEffect) 
      blurEffectView.frame = self.view.bounds 
      blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 
      self.view.addSubview(blurEffectView) 
      blurView = blurEffectView // HERE YOU SAVE WEAK REFERENCE 
     } 

     let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PriceAlarmPopUp") as! PriceAlarmPopupViewController 
     self.addChildViewController(popOverVC) 
     popOverVC.view.frame = self.view.frame 
     self.view.addSubview(popOverVC.view) 

     popOverVC.didMove(toParentViewController: self) 
    } 

    func fooDone() { 
     blurView?.removeFromSuperview() // Blur view will be removed from sureview and automatically `blurView` becomes to `nil` 
    } 
} 

他のView Controllerから非表示にする場合は、closures:

class MyVC: UIViewController { 
    func foo() { 
     let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PriceAlarmPopUp") as! PriceAlarmPopupViewController 
     self.addChildViewController(popOverVC) 
     popOverVC.view.frame = self.view.frame 
     if !UIAccessibilityIsReduceTransparencyEnabled() { 
      self.view.backgroundColor = UIColor.clear 
      let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) 
      let blurEffectView = UIVisualEffectView(effect: blurEffect) 
      blurEffectView.frame = self.view.bounds 
      blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 
      self.view.addSubview(blurEffectView) 
      popOverVC.userTappedCloseButtonClosure = { [weak blurEffectView] in 
       blurEffectView?.removeFromSuperview() 
      } 
     } 
     self.view.addSubview(popOverVC.view) 
     popOverVC.didMove(toParentViewController: self) 
    } 
} 

class PriceAlarmPopupViewController: UIViewController { 
    public var userTappedCloseButtonClosure: (() -> Void)? 

    @IBAction func closeButtonAction(_ sender: Any) { 
     userTappedCloseButtonClosure?() 
    } 
} 
+0

ご協力いただきありがとうございます。私はそれを試み、彼を削除するときに私のpopOverVCでfooDone関数を実行しました。デバッガによると、fooDoneセクションに入りますが、まだボケが解消されていません:( –

+0

@AlexanderKoメインスレッドで 'fooDone'を実行しましたか?' removeFromSuperview() 'が呼び出される前に' blurView'が 'nil' :@IBActionのFUNCのCloseButtonAction(_送信者:任意)。私はPopupViewに試み –

+0

{ self.view.removeFromSuperview() DispatchQueue.main.async {LETのVC = KeepaDataViewController() vc.fooDone() } } - 残念ながら同じ結果 –

1

ポップアップを終了すると、self.viewではなく、ぼかし表示が削除されます。つまり、blurEffectView.removeFromSuperview()です。

+0

を削除しかし、ここで私がすることができますこのコードを実行しますか?私はメインビューのコントローラではないでしょうか?しかし、PopupViewControllerでremoveFromSuperViewを実行した後、コード内のどのセクションにもジャンプしません。 –

+0

ベースビューコントローラの 'viewWillAppear()'に入れます。 – NRitH

0

怒鳴る

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) 
    let blurEffectView = UIVisualEffectView(effect: blurEffect) 
     blurEffectView.tag = 100 

    blurEffectView.frame = self.view.bounds 
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

    self.view.addSubview(blurEffectView) 

示すように、あなたのぼかしビューの弱参照を保持して、後でスーパーから削除タグ

self.view.viewWithTag(100)?.removeFromSuperview() 
+0

残念ながら、残念なことに、ポジティブな結果はありませんでした...私は何かが走っていないと感じています。あなたの親切な助けをありがとう! –

0

ぼかし効果をnilに設定します。あなたは、ビューコントローラのメインビューつまりを取り除くのではなく(実際にはblurviewのうち、アニメーション化するための唯一の適切な方法)

 UIView.animate(withDuration: 0.95, delay: 0, options: .curveEaseIn, animations: {() -> Void in 
     self.blurView.effect = nil 
     }, completion: {(finished:Bool) -> Void in  
     }) 
関連する問題