2017-08-09 9 views
0

UITableViewControllerをポップオーバーとして表示しているときに問題が発生しています。ポップオーバーが表示されますが、その幅はフルスクリーンではなく、先頭と末尾に何らかのマージンがあります。詳細はスクリーンショットをチェックしてください:ポップオーバープレゼンテーションコントローラ - 表示に前後にスペースがあり、全幅に収まらない

enter image description here

は、これは私がセットアップし、現在のコントローラに使用していたコードではありません:

let controller = UITableViewController() 
     controller.preferredContentSize = CGSize(width: self.view.bounds.width, height: self.popOverPresentationControllerHeight) 
     controller.modalPresentationStyle = .popover 
     controller.tableView.separatorStyle = .none 
     controller.tableView.allowsMultipleSelection = true 
     controller.tableView.dataSource = self.filterOptionsDataSource 
     controller.tableView.delegate = self 
     controller.tableView.isScrollEnabled = false 

     controller.tableView.register(FilterOptionCell.self, forCellReuseIdentifier: FilterOptionCell.identifier) 
     controller.tableView.register(UINib(nibName: FilterOptionCell.identifier, bundle: nil), forCellReuseIdentifier: FilterOptionCell.identifier) 
     controller.tableView.register(FilterConfirmCell.self, forCellReuseIdentifier: FilterConfirmCell.identifier) 
     controller.tableView.register(UINib(nibName: FilterConfirmCell.identifier, bundle: nil), forCellReuseIdentifier: FilterConfirmCell.identifier) 

     controller.popoverPresentationController?.popoverLayoutMargins = UIEdgeInsetsMake(0, 0, 0, 0) 

     controller.popoverPresentationController?.delegate = self 
     self.present(controller, animated: true, completion: { 
     UIView.animate(withDuration: 0.25) { 
      controller.view.superview?.layer.cornerRadius = 4 
      self.view.alpha = 0.4 
     } 
     }) 

     controller.popoverPresentationController?.backgroundColor = UIColor.white 
     controller.popoverPresentationController?.sourceView = sender 
     controller.popoverPresentationController?.sourceRect = sender.bounds 

も実装されてadaptivePresentationStyle機能が、それでも、何の違い:

追加質問

上矢印を変更/変更する方法はありますか?この矢印は私の使用には大きすぎるようですので、それを小さくしたり、カスタムのものに置き換える方法はありますか?

EDIT

一部を調査し、controller.view.superview?.frameをプリントアウトした後、私は、その幅は、それがポップアップの両側にそのスペースを説明しているべきであるよりも20ポイント小さくなって気づきました。しかし、それを取り除く方法は何ですか?

答えて

0

私はpopoverControllerを作成し、提示する方法、

override open func viewWillAppear(_ animated: Bool) { 
     super.viewWillAppear(animated) 
     var size = self.tableView.contentSize 
     size.width = 150.0 //Here, you can set the width. 
     self.preferredContentSize = size 
} 

と簡単な理解のために、このコードを試してみてください。

@objc open static func instantiate() -> PopOverViewController { 
     let storyboardsBundle = getStoryboardsBundle() //Or Bundle.main 
     let storyboard:UIStoryboard = UIStoryboard(name: "PopOver", bundle: storyboardsBundle) 
     let popOverViewController:PopOverViewController = storyboard.instantiateViewController(withIdentifier: "PopOverViewController") as! PopOverViewController 

     popOverViewController.modalPresentationStyle = UIModalPresentationStyle.popover 
     popOverViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up 

     // arrow color 
     popOverViewController.popoverPresentationController?.backgroundColor = UIColor.darkGray 


     return popOverViewController 
} 

、特定のViewControllerでのviewDidLoad(で

let popover = PopOverViewController.instantiate() 
     popover.popoverPresentationController?.sourceView = self.underlyingTextView 
     popover.popoverPresentationController?.sourceRect = rect 
     popover.presentationController?.delegate = self 
     viewController.present(popover, animated: true, completion: nil) 

//MARK: UIAdaptivePresentationControllerDelegate 
    public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle { 
     return UIModalPresentationStyle.none 
    } 

    public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { 
     return UIModalPresentationStyle.none 
    } 

を提示する)、あなたのtableViewを設定することができます。

関連する問題