objective c - iOS 8 Auto Layout issue -
i have annoying problem auto layout occurs in ios 8, while same setup works fine in ios 7.
i've simplified , isolated problematic situation, , here how should work - , how does work in ios 7:
the feature consists of 1 container view (blue), , 3 sub views:
a label an image view (with sliced, scaled image) a buttoni've added slider controls width of container view amending width constraint of container.
the auto layout constraints anchors label left-hand-side, button right-hand-side, , image view anchored both sides without having width constraint.
in ios 8, exact same setup looks this:
notice how image view (the black line) appears anchored offset outside right of container view.
i've tried , can't figure out why behaves differently in ios 8. i've removed , replaced constraints multiple times still same result.
these constraints set on each of sub views, respectivly:
and these constraints container view:
the width constraint of container view manipulated slider this:
- (ibaction)handlesliderchange:(id)sender { self.buttonwidth.constant = self.slider.value * 1024.0; [self.containerview setneedslayout]; [self.containerview setneedsupdateconstraints]; [self.containerview layoutifneeded]; [self.view setneedslayout]; [self.view setneedsupdateconstraints]; [self.view layoutifneeded]; }
others have had problems auto layout in ios 8 seems have been able solve similar issues calling setneedslayout
, / or setneedsupdateconstraints
directly on containing view, why i'm beingness explicit in calling on both containing view , root view. i've tried combinations of above, nil seems create difference.
i'm starting lose hope of finding solution, perhaps here has dealt similar situation , bring clarity issue?
edit: should add together i've tried set constraints image view label , button opposed edges of containing view same result.
edit 2: here's test project i've been using when trying isolate issue: download
it's not problem of auto layout, must bug in ios 8 handling sliced image assets.
with sample project:
uiimage *img = [uiimage imagenamed:@"pointer-dark-left"]; nslog(@"alignmentrect: %@", nsstringfromuiedgeinsets(img.alignmentrectinsets)); nslog(@"capinsets: %@", nsstringfromuiedgeinsets(img.capinsets));
this code prints
// ios 7 alignmentrect: {0, 0, 0, 0} capinsets: {0, 5.5, 0, 134} // ios 8 alignmentrect: {0, 0, 0, 65.5} capinsets: {0, 5.5, 0, 134}
alignmentrectinsets.right
65.5
!
as documented, autolayout works alignment rectangles, , uiimageview
uses images alignmentrectinsets
. so, self.line
has 65.5
pt right width.
of course, didn't set alignment insets in xcassets
editor, believe it's bug.
here ugly, working, workaround :(
- (void)viewdidload { [super viewdidload]; self.line.image = [self.line.image imagewithalignmentrectinsets:uiedgeinsetszero]; }
ios objective-c ios7 ios8 autolayout
No comments:
Post a Comment