popoverpresentviewcontroller与矩形角和没有箭头 [英] popoverpresentviewcontroller with rectangle corner and without arrow
问题描述
我想要一个没有圆角且没有箭头的弹出窗口。
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.
请帮助我实现:
- 带矩形角的弹出式视图
- 没有方向箭头的弹出视图
推荐答案
我不是对于 shawnynicole 的答案100%满意,因为我意识到从圆角到矩形角的变化是显着的/可见的。
I was not 100% happy with shawnynicole's answer because I realized the change from the rounded to the rectangular corners are notable/visible.
所以我提出了这个:视图控制器的子类(在我的例子中是一个 UINavigationController
)并覆盖 viewDidLayoutSubviews
并在那里更新角落。这样做更好,因为角落更改动画不可见,并且每次需要时都会更新(轮换等)。
So I came up with this: subclass the view controller (in my case it was an UINavigationController
) and override viewDidLayoutSubviews
and update corners there. This is better because corners change animation is not visible and it will be updated every time needed (on rotations, etc).
它适用于iOS11,可能应该适用于其他人版本。
It works in iOS11 and probably should work on others versions too.
class PopoverNavigationController: UINavigationController {
@IBInspectable var cornerRadius: Int = -1
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let r = CGFloat(cornerRadius)
if r >= 0 && view.superview?.layer.cornerRadius != r {
view.superview?.layer.cornerRadius = r
}
}
}
这篇关于popoverpresentviewcontroller与矩形角和没有箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!