Iphone User Iphone User - 1 year ago 127
iOS Question

toolsVersion="11201" is messing my storyboard

After updating my xCode to 8.0 and run my application on my device, i've noticed that my collection view in the storyboard is messed and the frame isn't fitting the view anymore.

This is happening only if i opened the storyboard(It seems that the xcode is adding some properties after the first time I opened the file in xcode).
When I replace the storyboard with my old one then build the app without opening it everything worked as expected.

After hours of searching what may be the reason and comparing the storyboards source codes (between the old one and the new one after opening it), I have found that the reason is the toolsVersion property found at the top of the storyboard source code.

<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0"
toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch"
propertyAccessControl="none" useAutolayout="YES" colorMatched="YES"

When I replace
toolsVersion="11201" with toolsVersion="10116"
then everything works again normally.

How can I force the tools version to a value? and what is this property and why it is messing up my constraints and frames.

Appreciate any information about this issue.

Answer Source

The problem here is that, with toolsVersion 11201 (Xcode 8), it seems that views that have fully qualified constraints no longer have frames specified in the storyboard (since the constraints will determine the frame at runtime).

So you can't rely on the frame until the constraints have been evaluated (i.e. don't use frames in viewDidLoad or viewWillAppear). Once the constraints have been evaluated, the frame seems to be fine. Before they have been evaluated, the frame seems to be reported as 1000 x 1000 (at least, that's what it was for me in various cases).

So there are two solutions: 1) Make an outlet to your constraints and use that instead of relying on the frame, or 2) use the frame after the constraints have been evaluated (for example, in the viewDidAppear method).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download