1

私はPopoverControllerを使用しています。バックグラウンドシャドウを取り除きたいと思います。 AppleはUIPopoverBackgroundViewをサブクラス化し、override class var wantsDefaultContentAppearance: Bool { get }Swift iOS - UIPopoverBackgroundViewのメソッドを他のクラスのPopoverControllerに接続する方法?

https://developer.apple.com/documentation/uikit/uipopoverbackgroundview/1619357-wantsdefaultcontentappearance

ためfalseを返すように言って、私はそれをサブクラス化し、falseにブール値を設定するが、影はまだ示しています。このサブクラスを、私のLogoutClassのアクションシート内で使用しているPopoverControllerにどのように接続すればよいですか?

UIPopoverBackgroundViewサブクラス:

class PopoverBackgroundView: UIPopoverBackgroundView { 

override class var wantsDefaultContentAppearance: Bool { 
     get { 
      return false 
     } 
    } 
} 

LogoutController:

class LogoutController:UIViewController{ 

fileprivate func logOff(){ 

let actionSheet = UIAlertController(title: nil, message: "Logging out?", preferredStyle: .actionSheet) 

let logout = UIAlertAction(title: "Log Out", style: .default){ 
      (action) in 
//bla bla bla 
} 

actionSheet.addAction(logout) 

if let popoverController = actionSheet.popoverPresentationController{ 
      popoverController.sourceView = view 
      guard let window = UIApplication.shared.keyWindow else { return } 
      window.backgroundColor = .clear 
      popoverController.sourceRect = CGRect(x:window.bounds.midX, y:window.bounds.midY, width:0, height:0) 
      popoverController.permittedArrowDirections = [] 

     } 
present(actionSheet, animated: true, completion: nil) 
} 
} 

答えて

3

はあなたがそうのようなあなたのUIPopoverPresentationControllerインスタンスのpopoverBackgroundViewClassプロパティを設定する必要があります:

のObjective C:

popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class]; 
アップルのドキュメントを1としてスウィフト

popoverController?.popoverBackgroundViewClass = PopoverBackgroundView.self 

このプロパティのデフォルト値は、デフォルトのポップオーバーの外観を使用するには、プレゼンテーションコントローラを引き起こしゼロ、です。このプロパティをnil以外の値に設定すると、プレゼンテーションコントローラは指定されたクラスを使用してポップオーバーの背景コンテンツを描画します。指定するクラスは、 UIPopoverBackgroundView のサブクラスである必要があります。

+0

ありがとうございました。私はそれを試しましたが、影がまだそこに残っているので、それがうまくいくかどうかわかりません。 –

+0

まだ動作していませんが、あなたの答えは正しいです。バックグラウンドクラスの実装に問題があります。ありがとう –

関連する問題