In my view controller, I add a subview that has xib, I set autorun to xib, but when I add a view to the view controller, it doesn't work

first I have my own custom view called FindFriendHeadPublish.h, which contains the xib file as follows: I set the autorun and the view is OC enter image description here

and my view controller, which is named PreviewViewController.swift, also has xib and I add the FindFriendHeadPublish view to the view controller, but autostart in FindFriendHeadPublish does not work.

    override func viewDidLoad() {
    super.viewDidLoad()
    self.title = "我的卡片预览"
    var addpreviewView = NSBundle.mainBundle().loadNibNamed("FindFriendHeadPublish", owner: nil, options: nil)
    var previewView = addpreviewView.last as! FindFriendHeadPublish
    previewView.setTranslatesAutoresizingMaskIntoConstraints(false);
    GetUserInfoInterface.getUserInfoWithFUid(UserInfoSaveUtil.getUserInfo().userid, withBlock: { (userInfo:GetUserInfoVo!  , error:NSError! ) -> Void in

})

self.scrollView.contentSize = CGSizeMake(320, 640)
self.scrollView.addSubview(previewView)

}

I have some other problems, but I did not find a solution, someone can help, thanks

In addition, the custom view works well in another view manager, which writes to OC

enter image description here

+4
2

Hieght Constraint previewView.setTranslatesAutoresizingMaskIntoConstraints(false);

var constraints: NSMutableArray = NSMutableArray()
constraints.addObject(NSLayoutConstraint(item: previewView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 0.0))
constraints.addObject(NSLayoutConstraint(item: previewView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Left, multiplier: 1.0, constant: 0.0))
constraints.addObject(NSLayoutConstraint(item: previewView, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Right, multiplier: 1.0, constant: 0.0))
self.scrollView.addConstraints(constraints as [AnyObject])

, .

+1

, IB, .

previewView.setTranslatesAutoresizingMaskIntoConstraints(false);
let viewBindingsDict = ["previewView":previewView, "view":self.view]
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[previewView(==view)]", options: nil, metrics: nil, views: viewBindingsDict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[previewView]", options: nil, metrics: nil, views: viewBindingsDict))

PreviewView . : http://www.thinkandbuild.it/learn-to-love-auto-layout-programmatically/

scrollview .

0

All Articles