我的一個分組的。項目我已經實現了你需要的方式。而不是使用我們可以像上面那樣實現的任何庫。
第1步:根據需要使用xib製作視圖控制器。像這樣
第2步:創建這就需要我們在定製警報自定義單元格。在那裏創建一個標籤,確保 行數爲該標籤選擇零,並給出頂部,底部,左側和右側約束。
第3步:現在在你的視圖控制器中寫下面的代碼。
//MARK: Variable declaration
let suggestionsView = SuggestionsVC(nibName: "SuggestionsVC", bundle: nil)
var blurEffectView : UIVisualEffectView?
//MARK: Show custom view & remove custom view
@IBAction func showAlert(sender: AnyObject)
{
showSuggestionView()
}
func showSuggestionView()
{
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView!.userInteractionEnabled = true
blurEffectView!.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.removeSuggestionsView)))
if !UIAccessibilityIsReduceTransparencyEnabled()
{
self.view.backgroundColor = UIColor.clearColor()
blurEffectView!.frame = self.view.bounds
self.view.addSubview(blurEffectView!)
}
else
{
self.view.backgroundColor = UIColor.blackColor()
}
suggestionsView.view.frame = CGRectMake(30,0, self.view.frame.size.width - 30, 260
)
suggestionsView.view.center = CGPointMake((self.view.bounds.width)/2,(self.view.bounds.height)/2)
suggestionsView.cancelButton.addTarget(self, action: #selector(self.removeSuggestionsView), forControlEvents: UIControlEvents.TouchUpInside)
suggestionsView.confirmButton.addTarget(self, action: #selector(self.removeSuggestionsView), forControlEvents: UIControlEvents.TouchUpInside)
suggestionsView.listTableView.registerNib(UINib(nibName: "SampleTableViewCell", bundle: nil), forCellReuseIdentifier: "SampleTableViewCell")
suggestionsView.listTableView.estimatedRowHeight = 44.0
suggestionsView.listTableView.rowHeight = UITableViewAutomaticDimension
self.view.addSubview(suggestionsView.view)
suggestionsView.listTableView.dataSource = self
}
func removeSuggestionsView()
{
suggestionsView.view.removeFromSuperview()
blurEffectView!.removeFromSuperview()
self.view.backgroundColor = UIColor.lightGrayColor()
}
//MARK: TableView DataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: SampleTableViewCell = (tableView.dequeueReusableCellWithIdentifier("SampleTableViewCell") as? SampleTableViewCell)!
if indexPath.row % 2 == 0
{
cell.sampleText.text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa."
}
else
{
cell.sampleText.text = "Lorem ipsum "
}
return cell
}
另外,您可以自定義blurEffect和動畫以顯示上述視圖。我希望這能幫到您。它看起來像這樣。
嘿,你檢查了我的答案。 ? –