2017-12-02 136 views
0

目前縮略圖中的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:),這兩者似乎都不適合我的要求。任何幫助將不勝感激。謝謝。

+0

您沒有設置ImageView的框架,設置框架和嘗試。 –

+1

@as diu是否要在表格視圖中以彈出形式顯示圖像? – Niroj

+0

@Niroj是的,我想要一個圖像作爲彈出與捏縮放和X按鈕來消除圖像。這就是我想要完成的。 –

回答

1

這是一個演示表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: { 
     }) 
    } 

} 

} 

A table view

A simple view for Image

+0

這個答案的工作完美的東西我一直在尋找。謝謝@Niroj –

+0

沒有問題:) :) ... – Niroj

+0

可以請了投票支持更多的知名度的問題。謝謝@Niroj –

相關問題