osx - How to set up a NSLayoutConstraint in a NSScrollView? -
i new nslayoutconstraint.
i want manage content of nsscrollview programmatically. @ end, want create subclass of nsscrollview method - add:(nsview *)aview add aview after others , enlarge documentview of nsscrollview if necessary.
(all osx) guess exists can't find it, if knows find this, in ;) here picture can understand : 
my plan use nslayoutconstraints. constraints :
- equal vertical space between
view 1,view 2, etc. - the
documentviewheight should adapt sum of heights ofview 1,view 2, etc. - some fixed vertical margins between
documentviewandview 1, lastview. view 1,view 2, etc. right-aligned
so, let come question : have started adding view 1 (i see after rest). did following :
thescrollviewnsscrollview;newsubviewview want add ; respect picture,view 1.thecontainer = [[nsview alloc] initwithframe:nsmakerect(0, 0, 0, 0)] ; [thescrollview setdocumentview:thecontainer] ; [newsubview settranslatesautoresizingmaskintoconstraints:no]; [thecontainer addsubview:newsubview] ; nslog(@"superview ? %@", [newsubview superview]) ; nslog(@"view ? %@", newsubview) ; nslog(@"nsscrollview ? %@", self) ; nslog(@"nsscrollview content ? %@", self.contentview) ; nsarray * arrayofconst1 ; arrayofconst1 = [nslayoutconstraint constraintswithvisualformat:@"v:|-50-[newsubview]" options:nslayoutformatdirectionleadingtotrailing metrics:nil views:nsdictionaryofvariablebindings(newsubview)]; nslog(@"first constraints : %@", arrayofconst1) ; nsarray * arrayofconst2 ; arrayofconst2 = [nslayoutconstraint constraintswithvisualformat:@"h:|-[newsubview]" options:nslayoutformatdirectionleadingtotrailing metrics:nil views:nsdictionaryofvariablebindings(newsubview)]; nslog(@"second constraints : %@", arrayofconst2) ; [newsubview removeconstraints:[newsubview constraints]] ; [thecontainer removeconstraints:[thecontainer constraints]] ; [thecontainer addconstraints:arrayofconst1] ; [thecontainer addconstraints:arrayofconst2] ; nslog(@"frame of thecontainer : %@", nsstringfromrect(thecontainer.frame));
but, doesn't work, frame of thecontainer remains (0,0,0,0).
i new nslayoutconstraints ; missing ?
Comments
Post a Comment