Xcode 8, XIBs and Auto layout - UI gone for toss

Hi,


We use XIBs througout our project and we have lots and lots of them. As Xcode 8 became publicly available we downloaded the Xcode 8 from App store and udpated our development environments. Now when I open any XIB it asks me "Choose an initial device view" and I started choosing "iPhone 6s plus" as the device. The XIBs are now resized to a particular device size and all the controls inside it are also resized accordingly because all of them are controlled via autolayout. Everything looks good in XIB. Now when I run the application (simulator or device) and go to the particular view couple of controls do not appear at all on screen. If I break the constraint in XIB by moving them 1 point from where they are supposed to be and then run the application, they load without any errors. I tried everything that was possible in XIB including deleting and adding all the constraints but I am still seeing the same problem. If I revert the XIB to Xcode 7.x compatibility then it works fine. But with Xcode 8 it doesnt allow me to make changes to XIB which is compatible with Xcode 7.x.

I have attached the below screenshots at https://www.dropbox.com/sh/rpq6tdgja8fcvaj/AADYD9T0nSmFXy2YyOICo5p7a?dl=0


ChooseInitialDevice.png: Prompt to choose initial device view for XIB

Screenshot1-Working.png: Working Screen before XIB was converted to Xcode 8.x compatible.

Screenshot2-XIB.png: XIB converted to Xcode 8.x and all constraints are in place.

Screenshot3-Not-Working.png: Screen missing the Profile Image after the XIB was converted to Xcode 8.x compatible.

Screenshot4-Constraint-Break.png: Breaking the constraint by 1 point (move image view to x = 21 instead of x=20) and everything works fine when the application runs on simulator or device.


I understand the problem might be hard to understand and difficult to believe. If the images are not clear I can post a video for the same. I am seeing the same behavior for all the XIBs that are coverted to Xcode 8.x.

I have also submitted a bug with Apple: 28342777

I have the exact same problem. After opening my storyboard in Xcode8 and accepting the "Choose an initial device view" Dialog, everyting is acting strange. When I update all frames, the IB looks good, but after building, the app is totally broken. Tested it with 4 apps.

Please open a bug with apple. Every bug counts.

Closely following this thread as well - moving UI components in the Storyboard so that the Storyboard frame DOESN'T match the constraints seems to make components appear when run in app. Updating constraints, turning Auto Layout On/Off, moving the component + updating its frame all doesn't seem to work. I've downgraded to 7.3.1 in the meantime to actually be able to work.

Response from Apple in bug report: "We need more information to investigate this issue. Thank you for reporting the issue. Could we get more information about the profile image view? In Xcode 8, a fully constraint, non-misplaced view no longer saves out a frame to minimize diffs and support automatically update frames in IB. At runtime, these views get decoded with a placeholder size of 1000x1000, but are resolved after first layout. Could the image be assigned before initial layout, and would assigning the image to the image view after first layout address this case? Please send a sample to help us further analyze. thanks! Please provide your response or results by updating your bug report" I provided them a sample. Regards, Bhavik

This fix works for me. Just one single line of code 🙂
http://stackoverflow.com/a/39548367/5536251

Any luck with the 8.1 Xcode beta?

This is definitely not only related to Image views. We have issues with 3 Views: 2 Buttons and 1 normal UIView. All of them are 1000x1000 by the time viewDidLoad runs and the explicit height/width contstraints don't work at all / do wired things when loading the view.

No, Issue still present as the folks at Apple still investigating.

I'm having the same issue I upgraded my project using xCode 8 from xCode 7. Also, I only did the Swift 2.3 conversion because 3.0 I needed to slot more time for. Now when I open a storyboard it tells me to "choose a device version". If I try to set the option "open as xCode 7" it closes my storyboard and when I open it again. I'm mandated to "Choose a device version". Then when I run the app my tableView's are blank.

Same. Selecting a layout default ruined all my dynamic label placement, and i now have wierd transition animations between when switching view controllers. The Xcode 8 storyboard file wont run in the simulator *at all* after conversion without being completely visually messed up and missing 80% of the elements. I have to revert to xcode 7 storyboard compatability and modify the xml directly to make changes. This is completely insane.

I have an update:


When instantiating a uiview via XIB files (whether loading them from a view controller, or from inside of a UIView itself), or just creating IBOutlet variables for UIViews that are in your storyboard viewcontroller, XCode is not loading UIViews from the storyboard with the proper size constraints. It is resetting the UIView frame bounds to 1000x1000, instead of whatever size they are set to in the storyboard. This obviously breaks everything in autolayout, and any subsequent subviews that might be loaded thereafter.


So to fix:


In every UIView element that is linked to a view controller from the storyboard, you need to call .layoutIfNeeded() on each one. For example, in my xibSetup routine:


view = loadViewFromNib()

view.frame = bounds

view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]

view.layoutIfNeeded() //needed to have proper bounds height and width


or, if you have an IBOutlet for a UIView of any kind (linked from the storyboard):


uiviewfromstoryboard.layoutIfNeeded()


etc.

Calling .layoutIfNeeded() will force the app to re-evaluate the size constraints, and it will set them properly. Hopefully this makes sense and helps somebody.

Please check against Xcode 8.1, beta 2 (8T46g):

Xcode 8.0 did not always restore view frames from storyboards and xibs when layouts were ambiguous. Xcode 8.1 fixes several of these issues. If you have encountered these issues, resolve the ambiguity in the Auto Layout issues and update frames. Xcode 8.1 will persist them correctly. (28221021, 28244619)

Xcode 8.1 beta 3 solves this issue for me.

I couldn't be more angry, Apple might have ruined my entire company. The app has now been ruined by xcode 8 with layout issues, not onyl this but I submitted a version of the app onto the store and it was reviewed and passed. The app is compeltely unsuable despite it passing! Are you purposly tring to ruin my career?

Not ruined but I'm really disappointed with Apple OS and dev tools/sdk since 2013. Missing quality and detail.

Indeed. Fixed since Xcode 8.1 Beta 3, because they just reintroduced the tags which were removed in Xcode 8

<rect key="frame" x="20" y="0.0" width="560" height="30"/>


You may need to convert the Storyboards again from 7.1 format to 8.1 format, or removing/readding the problematic constraints should fix it.

I had a very similar issue with my app after upgrading to xCode8. I had a storyboard with a tableview and a one dynamic prototype cell. It had an ImageView on the left and a view containing label to the right. One day after opening the storyboard in xCode 8, not to edit it, but just to look at the current layout, xCode 8 did its upgrade thing asking for the default device to simulate the layout. After the change it all looked good in xCode IB, so I thought nothing of it. It was only after submission to the app store I was going through the app in a TestFlight build and just happend to test the feature with this tableview. It was at this time I discovered all the cells looked empty!! Now remember I had not edited this feature so it was pure luck that I looked at this particular screen and caught this issue, which makes me very, very concerned using xCode 8.


The cells it turned out were not empty, but being covered by the view that contained the label. That view had a frame of (0, 0, 1000, 1000), which being the last view (besides the label) in the view hierarchy, was more than enough to cover the contents. But there was also some other odd layout behavior as well. It was if the entire tableview (or its content inset) had shifted up by about 44px. This is a familiar value, no?


Anyway, to resolve the issue I had to tear down all the constraints and redo them. So far the bug has not returned. But I am being very careful to take note what xibs and storyboards I touch. Because those will need to be tested at runtime.


(I'm a seasoned developer BTW and quite at home with autolayout, so yeah, I'm more than concerned at this point)


-Ed.

I have XCode 8.1 and it is still a piece of garbage! Between XCode 8 and iOS 10 I can't get a stable build. I have an app that runs perfectly on pre-iOS 10, but crashes with iOS10 with a StoryBoard instantiation error for a nib named x8-ye-9j-87... some Storyboard garbage.


I have reverted back to XCode 7.3. I have lost at least 3 weeks of work and hopefully not this customer. I am eating the cost that APPLE and their worthless QA group is costing me in time!!

No... This is a living nightmare called XCode 8. I have nearly lost a client because of the massive delays in bringing product to market. I've been using contraints since they were introduced, and even with autolayout and constraints in place, XCode 8.1 still ruined nearly every scene I've built! I am reverting back to XCode 7.3. I can't waste anymore time dealing with having to rebuild my application UI's.


The key element is that the kids at Apple think they know what every developer may do and how they should do it. M/S and IBM made these same errors decades ago and now these kids are making the same stupid assumptions and I like many others have lost confidence in what they deliver. With 8.1 it is so bad you literally can't trust what is being generated. This is Apple's "Windows Vista"!! This is a terrible product!!


The QA group should not receive any bonus or salary increase, and the leader fired! I'm angry because you are taking money from me because I have to eat my cost overruns caused by XCode 8.1, and they are significant.

Is this issue fixed yet? I am facing the same issue still with XCode Version 8.2.1. I still keep going in the loop with this work-around.


When I go to Storyboard it prompts me to "pick a device view", no matter which one I pick (Iphone7 or IPad9.7 etc.) it will ruin the existing auto-resizing layouts and switch the "Interface Builder Document to XCode 8.0". Then As suggested above, I tried to reset "Interface Builder Document to Xcode 7.x" and save, everything comes back normal as I had originally in working condition.


But as soon as I go back to Storyboard, it prompts me again to "pick a device view", and the loop mentioned above starts all over again.

Very frustrated with this. How could Apple even ship such broken software?

If I didn't have my files in git .. i would have NEVER noticed all the crazy changes Xcode 8 did to my xib file! Holy moley!

I am downloading Xcode 7.3.1 right now.. no way am I trying to work through this ridiculousness!

Well ****.. that's no good.. I tried to open a couple xib files in Xcode 7.3.1 and it told me they were only openable in Xcode 8.0 or above.

You can toggle that setting easily.

Xcode 8, XIBs and Auto layout - UI gone for toss
 
 
Q