如何在点击tableViewCell时将UIImageView放到前台?

目前缩略图中的UITableViewCell并在轻敲细胞中被示出,我想要显示在前景中的图像与右顶部的横/ X按钮关闭该图像并显示的tableView。我有下面的代码在didSelectRow:如何在点击tableViewCell时将UIImageView放到前台?

let hoverImage = UIImageView() 

hoverImage.image = UIImage(named: "splashpt")

hoverImage.contentMode = .scaleAspectFit

self.view.addSubview(hoverImage)

hoverImage.center = self.view.center

hoverImage.layer.zPosition = 5

self.view.bringSubview(toFront: hoverImage)

静止图像不显示。计算是击中代码的这一部分,因为我能够调试并逐步完成这部分代码。但屏幕上没有显示。我正在使用zPositionbringSubview(toFront:),这两者似乎都不适合我的要求。任何帮助将不胜感激。谢谢。

回答:

这是一个演示表view.On轻敲表视图单元的视图POP操作了关闭按钮。然后按下关闭按钮弹出视图关闭。

import UIKit 

class ViewController: UITableViewController {

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

return 1

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return 5

}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell

cell.textLabel?.text = "Happy"

return cell

}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

print("Cell\(indexPath.row) is selected")

let storyBoard = UIStoryboard(name: "Main", bundle: nil)

let popoverVC = storyBoard.instantiateViewControllerWithIdentifier("PopViewController") as! PopViewController

popoverVC.delegate = parentViewController as? InfoViewDelegate

let nav = UINavigationController(rootViewController: popoverVC)

nav.modalPresentationStyle = UIModalPresentationStyle.Popover

nav.navigationBar.hidden = true

self.presentViewController(nav, animated: true)

{

}

popoverVC.passingViewController = self

}

}

这是一个PopUpViewController:

import UIKit 

protocol InfoViewDelegate: class

{

func infoViewClicked(tag: Int)

}

class PopViewController :UIViewController

{

@IBOutlet weak var btnClose: UIButton!

var delegate = InfoViewDelegate?()

var passingViewController: UIViewController!

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

override func viewWillAppear(animated: Bool) {

}

override func viewDidDisappear(animated: Bool) {

self.presentingViewController?.dismissViewControllerAnimated(true

, completion: {

})

}

/*

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

// Get the new view controller using segue.destinationViewController.

// Pass the selected object to the new view controller.

}

*/

@IBAction func btnClicked(sender: UIButton) {

if(sender == self.btnClose)

{

self.delegate?.infoViewClicked(1)

self.presentingViewController?.dismissViewControllerAnimated(true

, completion: {

})

}

}

}

以上是 如何在点击tableViewCell时将UIImageView放到前台? 的全部内容, 来源链接: utcz.com/qa/258773.html

回到顶部