popoverpresentviewcontroller有矩形的角和没有箭头

时间:2023-02-09 23:39:20

I want a popover without rounded corners and with no arrow.

我想要一个没有圆角和没有箭头的弹窗。

I have done the following code but it did not work:

我已经做了以下代码,但它没有工作:

//SerachPopViewController.swift

/ / SerachPopViewController.swift

    //MARK: InitCoder
required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    //popover settings
    //popoverPresentationController!.permittedArrowDirections = .Any
    modalPresentationStyle = .Popover
    popoverPresentationController!.delegate = self
    //permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
    self.preferredContentSize = CGSize(width:340,height:380)
}

//QueryTableViewController.swift

/ / QueryTableViewController.swift

    @IBAction func searchFilter(sender: AnyObject) {

    let searchPopController = storyboard!.instantiateViewControllerWithIdentifier("SerachPopViewController") as! SerachPopViewController
    searchPopController.serachPopDelegate = self
    searchPopController.modalPresentationStyle = .Popover
    searchPopController.preferredContentSize = CGSize(width:340,height:380)

    let popoverPresentationController = searchPopController.popoverPresentationController

    popoverPresentationController!.sourceView = self.view;
    popoverPresentationController!.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
    popoverPresentationController!.permittedArrowDirections = UIPopoverArrowDirection();
    self.presentViewController(searchPopController, animated: true, completion: nil)
}

I am able to display popover view with arrow and rounded arrow.

我可以用箭头和圆形箭头显示弹出窗口。

Please help me to achieve:

请帮助我实现:

  • popup view with rectangle corner
  • 有矩形角的弹出视图
  • popup view without direction arrows
  • 没有方向箭头的弹出视图

5 个解决方案

#1


20  

Using the concept above, you can also set the corner radius in the completion parameter.

使用上面的概念,您还可以在完成参数中设置角半径。

Swift 3

斯威夫特3

let popoverViewController: UIViewController = // Some view controller to be presented in a popover

// Set popover properties here...
// i.e. popoverViewController.modalPresentationStyle = .popover

present(popoverViewController, animated: true, completion: {
     popoverViewController.view.superview?.layer.cornerRadius = 0

    // Additional code here
})

#2


4  

In iOS 11 its not possible to use @SHN solution for removing rounded corners. The corner radius is set to default value after viewWillAppear.

在ios11中,不可能使用@SHN解决方案来删除圆角。在viewWillAppear之后,角半径设置为默认值。

Radius must be set in viewDidAppear method

在viewDidAppear方法中必须设置半径

override func viewDidAppear(_ animated: Bool) {
    view.superview?.layer.cornerRadius = 0
    super.viewDidAppear(animated)
}

#3


3  

To get popover without arrow when you are initiating popover, use:

要在启动弹窗时获得无箭头弹窗,请使用:

popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)

For popover without corner radius, in the popover content view controller use:

对于没有角半径的弹窗,在弹窗内容视图控制器中使用:

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // Do any additional setup after loading the view, typically from a nib.
        self.view.superview?.layer.cornerRadius = 0.0;
    }

#4


1  

I don't know why It does't work on my Simulator with iOS11.1 until trying setting backgroundColor.I added function viewWillTransition for rotating device.

我不知道为什么它不能在我的模拟器上使用iOS11.1,直到尝试设置backgroundColor。我为旋转设备添加了函数viewWillTransition。

override func viewDidAppear(_ animated: Bool) {
    view.superview?.backgroundColor = UIColor.white
    view.superview?.layer.cornerRadius = 0
    super.viewDidAppear(animated)
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    view.superview?.backgroundColor = UIColor.white
    view.superview?.layer.cornerRadius = 0
    super.viewWillTransition(to: size, with: coordinator)
}

#5


0  

For Swift 4, in case you present your popover embedded in a navigation controller:

对于Swift 4,如果您将弹出窗口嵌入导航控制器:

override func viewDidAppear(_ animated: Bool) {
        navigationController?.view.superview?.layer.cornerRadius = 0
        super.viewDidAppear(animated)
}

#1


20  

Using the concept above, you can also set the corner radius in the completion parameter.

使用上面的概念,您还可以在完成参数中设置角半径。

Swift 3

斯威夫特3

let popoverViewController: UIViewController = // Some view controller to be presented in a popover

// Set popover properties here...
// i.e. popoverViewController.modalPresentationStyle = .popover

present(popoverViewController, animated: true, completion: {
     popoverViewController.view.superview?.layer.cornerRadius = 0

    // Additional code here
})

#2


4  

In iOS 11 its not possible to use @SHN solution for removing rounded corners. The corner radius is set to default value after viewWillAppear.

在ios11中,不可能使用@SHN解决方案来删除圆角。在viewWillAppear之后,角半径设置为默认值。

Radius must be set in viewDidAppear method

在viewDidAppear方法中必须设置半径

override func viewDidAppear(_ animated: Bool) {
    view.superview?.layer.cornerRadius = 0
    super.viewDidAppear(animated)
}

#3


3  

To get popover without arrow when you are initiating popover, use:

要在启动弹窗时获得无箭头弹窗,请使用:

popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)

For popover without corner radius, in the popover content view controller use:

对于没有角半径的弹窗,在弹窗内容视图控制器中使用:

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // Do any additional setup after loading the view, typically from a nib.
        self.view.superview?.layer.cornerRadius = 0.0;
    }

#4


1  

I don't know why It does't work on my Simulator with iOS11.1 until trying setting backgroundColor.I added function viewWillTransition for rotating device.

我不知道为什么它不能在我的模拟器上使用iOS11.1,直到尝试设置backgroundColor。我为旋转设备添加了函数viewWillTransition。

override func viewDidAppear(_ animated: Bool) {
    view.superview?.backgroundColor = UIColor.white
    view.superview?.layer.cornerRadius = 0
    super.viewDidAppear(animated)
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    view.superview?.backgroundColor = UIColor.white
    view.superview?.layer.cornerRadius = 0
    super.viewWillTransition(to: size, with: coordinator)
}

#5


0  

For Swift 4, in case you present your popover embedded in a navigation controller:

对于Swift 4,如果您将弹出窗口嵌入导航控制器:

override func viewDidAppear(_ animated: Bool) {
        navigationController?.view.superview?.layer.cornerRadius = 0
        super.viewDidAppear(animated)
}