ios - Autolayout causes small gaps on rotation -



ios - Autolayout causes small gaps on rotation -

my application uses auto-layout create interface comprising 1 2:1 container (fitting screen size) 2 square boxes inside. illustration can seen below (only left box visible):

when device rotated code updates constraints either position boxes left right (landscape) or top bottom (portrait). code works reasonably well, interface ends after rotation:

as can see, background of container seen in left , bottom corner; varies in severity (sometimes it's more visible).

i've set small project exhibits issue; comprises little view hierarchy within storyboard constraints removed @ build time.

the actual constraints created / updated within viewcontroller.m , dualvideoview.m.

the constraints seem pretty accurate me, i'm not sure why these layout issues happen in first place.

update

removing view finder (orange frame in above screenshots) resolves layout issue; uses proportional width & height (e.g. width := superview.width * 0.9) draw inset square frame. i'm not sure why should issue, though.

although vertical constraints not issue, point out missing height constraints video1/video2:

[nslayoutconstraint constraintwithitem:self attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:_video1 attribute:nslayoutattributeheight multiplier:1 constant:0] [nslayoutconstraint constraintwithitem:self attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:_video2 attribute:nslayoutattributeheight multiplier:1 constant:0]

your horizontal constraints good, though, took dualvideoview source code , created minimal application around (source code @ codepad.org) in order reproduce problem. unfortunately minimal application not show gaps see, unless can provide farther details reduced guessing. usual, helpful thing can show minimal complete code illustration exhibits problem - maybe can start expanding on sample app linked above.

the main thing can think of somewhere along way rounding error creeping in because video1/video2 views should take half of width of superview.

for instance, happens if dualvideoview instance gets odd width of, say, 1023? assuming half points floored, half width of 1023 511 (511.5 floored). total width of video1/video2 becomes 1022, hence leaving 1 point gap. there 2 problems assumption, though:

it not explain vertical gap since vertical constraints not include might lead rounding error. the assumption wrong, auto layout not flooring (nor ceiling), rounding. half width of 1023 512 (511.5 rounded up), means if video1/video2 should overlap , there should no gaps.

some things might check:

can still see gaps if rotate twice 180° (i.e. if rotate original position)? if gaps disappear, problem might not rounding error faulty positioning calculation depends on device/interface orientation.

can still see gaps if test retina display simulator or device? there might difference because on retina displays auto layout rounding differently (it allows .5 values , rounds on .25 steps). if gaps still there , testing on simulator, might interesting measure pixie app see if gaps 1 or 2 pixels wide.

does create difference if utilize constraints align video1/video2 edges instead of center of superview (e.g. align top/left border of video1 top/left border of superview)?

update

in github sample project tracked downwards problem constraints exist in storyboard little white subview of video1 view. specifically, problem somehow related 0.9 multiplier - if reset multplier default 1.0 , instead utilize constant, instance -20, resizing problems magically go away. "magically", because utterly baffled why multiplier should create such difference. if find more time take jab @ this, right recommendation: utilize constant value instead of multiplier.

one other thing noticed (but not all) of constraints express dependencies in reverse. instance:

[nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributecenterx relatedby:nslayoutrelationequal toitem:self.videocontainerview attribute:nslayoutattributecenterx multiplier:1 constant:0],

this constraint expresses center.x of vc main view (superview) depends on center.x of video container view (the subview). find unusual way think relationship between superview , subview, think other way round. admittedly, auto layout equation solver seems able cope this, still recommend write constraints in natural dependency order. if nil else, help other people improve understand code.

update 2

a little bit of additional research:

the layout issue occurs in iphone simulator, not in ipad simulator the layout issue disappears if proportionally sized view aligned not center top , left edges of superview (video1) examining 1) main view, 2) video container view, , 3) video1 view (which contains white proportionally sized view) debugging aid constraintsaffectinglayoutforaxis never reveals any constraint involves proportionally sized view - although removing view, or aligning differently, has demonstrable effect on layout

especially lastly point leads me believe combination of constraints exposes bug in auto layout engine. suggest file bug study apple using minimal illustration posted on github.

ios rotation autolayout

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -