简体   繁体   中英

Xcode 13 iOS 15 Programmatic Obj-C Constraints translatesAutoresizingMaskIntoConstraints

I use 100% programmatic constraints in my interface code. Upgraded to Xcode 13 and iOS 15. Got tons of NEW execution warnings about constraints, all saying that the system had to break some constraints to comply with others. I had not seen such warnings for several years, and have not touched my constraint code in all that time. Yet thorough testing shows my code continues to run correctly. What's up?

Answer: I had been a bit cavalier with the timing of when iOS actually calculated the constrained dimensions. I put all of my programmatic interface declarations into a single method. At the bottom of that method, I have long had code that went beyond interface layout, into NavCon preliminaries. Among those NavCon declarations, I had lines like:

self.view_D0_Tutorial.frame = self.view_CenterPane_D0_Tutorial.frame;

I noted at the time that I wrote and debugged those lines, that using the debugger to ask what the location data was, all I ever got was CRect (0,0,0,0), yet the code somehow did the right thing.

Well, in the upgrade, iOS apparently changed the way they do things. I had to do two things in response.

(1) moved all the NavCon preliminary code to a new separate method, and call it with performSelector and 0 delay.

(2) changed the simple frame assignment to a more limited assignment:

self.view_D0_Tutorial.frame = CGRectMake(0, 0, self.view_CenterPane_D0_Tutorial.frame.size.width, self.view_CenterPane_D0_Tutorial.frame.size.height);;

The combination made the error messages go away, and my code continues to run correctly!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM