alignment - How to align the top of a view to half the parent view's height in Xcode 6.1 -


i trying align top of white subview half height of container view in viewcontroller. see attached image. in old versions of xcode possible ctrl-drag view container view , select "top alignment container view", in new xcode 6.1 offer alignment "toplayout guide". used constraint , setup constraint can see in right hand side of image. based on reading, following equation applies:

property1 = property2 * multiplier + constant.

so wanted settings: view.top = toplayoutguide.bottom * 0.5 + 0

such top of white "view" aligns half height of toplayoutguide.bottom. however, when this, result ).5 totally ignored, , white view's top aligned toplayouguide.bottom, covering whole screen basically.

can figure out doing wrong, , proper way align view's top half height of container?

thanks

-malenasee image below

i encountered same problem xcode 6.1. found there several ways use storyboard editor split view (nearly) in half adding subview use sort of benchmark. imemon's programmatic solution works, requires additional code constraints on objects use halfway point reference, can tedious.

to solve problem:

  1. add view controller's main view.
  2. give color stands out against background.
  3. give height of 1.
  4. move center of main view , give "vertical center in container" constraint.
  5. now can drag top or bottom of object align frame of view added. can apply constraints control+click+dragging object new view , selecting appropriate constraint pop-up menu.
  6. change color of benchmark view make invisible in application. used clear color, object wanted align clear, , had background. if clear doesn't work you, try constraining width of benchmark view match width of object aligned, give them same color.

you can extend idea of using views benchmarks other situations, such aligning point 3/4 distance between 2 objects. can add objects views, apply constraints within those, , move views around , apply constraints in superview well. creative , experiment it.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -