How to create xib subview in center of view swift table

I have a tableview and I created a custom xib uiview as a "detailview" for it. I want to show this detailed view in the center of the scroll area when I click on a table cell. I can show this opinion, but I cannot centralize it. when I set the value for the frame manually, the subview will be in the center (approximately), but when I click on the cell that is at the bottom, the subview appears at the top of the page, and also moves when I view the table view.

Please help me show this view in the center of the scroll area and lock

Here are my codes;

Detailed view:

class TopTenDetailView: UIView {

      var screenWidth:CGFloat = UIScreen.mainScreen().bounds.width*0.08
      var screenHeight :CGFloat = UIScreen.mainScreen().bounds.height*0.08

      class func instanceFromNib() -> UIView {
            return UINib(nibName: "TopTenDetail", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! UIView
      }

      override func awakeFromNib() {
            super.awakeFromNib()
            self.layer.cornerRadius=10

            let testFrame : CGRect = CGRectMake(screenWidth,screenHeight,320,480)
            self.frame = testFrame
            self.userInteractionEnabled=true
      }

      @IBAction func close(sender: UIButton) {
            self.hidden=true
      }
}

And the TableViewController method;

      override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
             var detailView = TopTenDetailView.instanceFromNib
             self.view.addSubview(detailView())
      } 
+4
source share
1

, , - .

, OverFullScreen, :

  • UIViewController , DetailViewController Interface Builder. CLEAR
  • "" UIViewController, UITableView DetailViewController segue . "detailSegue", . , , . Interface Builder.

enter image description hereenter image description here

, :

    // MARK : - UITableViewDelegate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.performSegueWithIdentifier("detailSegue", sender: self)
    }

    // MARK: - segues
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if let vc = segue.destinationViewController as? UIViewController{
            vc.modalPresentationStyle = .OverFullScreen

        }
    }

OverFullScreen UIViewController modal segue, UIViewController .

, , DetailViewController Interface Builder .

, !

enter image description hereenter image description here

+1

All Articles