Reputation: 25983
I haven't been using Auto Layout because I need to support iOS 5. I'm now getting an NSInternalInconsistencyException when I push a controller:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Auto Layout still required after executing -layoutSubviews.
SGBExampleView's implementation of -layoutSubviews needs to call super.'
My implementation of layoutSubviews does call [super layoutSubviews], so that's unhelpful. It seems that something has turned on Auto Layout for my view; I'd like to turn it off again. However, everything I can find that says how to turn it off says to do so from IB. I don't use IB. How do I turn off Auto Layout for a view from code?
UPDATE:
This question is not a duplicate as the other pertains specifically to a UITableViewCell subclass, and setting translatesAutoresizingMaskIntoConstraints
to either YES or NO has no effect.
Upvotes: 3
Views: 3444
Reputation: 1893
I've recently been added to a project that was initiated with auto layout, but I needed to dynamically adjust some frames in code. This is what I did to not be impaired by automatically generated run time constraints (courtesy of auto layout):
1) Do NOT have views or components laid out in interface builder.
2) Add your views purely programmatically starting with alloc/init and setting their frames appropriately.
3) Done.
Hope that helps!
ps. you can also experiment with stripping constraints from views with:
[view removeConstraints:view.constraints] but i've had more luck with the pure code approach.
Upvotes: 0
Reputation: 26652
To turn off Auto Layout for a view, just don't have any constraints that relate to that view:
To provide additional compatibility, the entire constraint-based layout system is not active at all until you install a constraint on a view.
See Cocoa Auto Layout Guide. Yes, that relates to Cocoa and not iOS. However, the principle will be the same.
Upvotes: 1