Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios7 empty autolayout layout already ambiguous

I just created an empty iOS Project for a 'Single View Application' which targets iOS7, but when i ran the empty project and inspected my viewtree by typing:

po [[UIWindow keyWindow] _autolayoutTrace]

i got the result that the two layout guides are already ambiguous

*<UIWindow:0x108f537f0> - AMBIGUOUS LAYOUT
|   *<UIView:0x109409850>
|   |   *<_UILayoutGuide:0x109409c10> - AMBIGUOUS LAYOUT
|   |   *<_UILayoutGuide:0x10940a540> - AMBIGUOUS LAYOUT

Is there a reason to get rid of those warnings - or can i simply ignore them?

like image 816
Simon Meyer Avatar asked Sep 24 '13 09:09

Simon Meyer


2 Answers

You can ignore them if you dont want to use Autolayout or go to the Interface Builder and add the layouts yourself (you can even let XCode add the layouts it thinks are needed)

enter image description here

like image 93
Antonio MG Avatar answered Nov 01 '22 04:11

Antonio MG


It was the same with iOS 6.

I guess it sometimes takes time for constraints to "settle down" and not be ambiguous. According to WWDC 2012 video "Best Practices for Mastering Auto Layout," ambiguity can be temporarily tolerated (unlike unsatisfiability, which immediately raises an exception).

If you want to prove to yourself that your constraints are not remaining ambiguous, then create a wrapper for [[UIWindow keyWindow] _autolayoutTrace] and call it after a short delay:

- (void)viewDidAppear:animated
{
    [super viewDidAppear:animated]; 

    [self performSelector:@selector(wrapperForLoggingConstraints) withObject:nil afterDelay:.3];
}

- (void)wrapperForLoggingConstraints
{
    [[UIWindow keyWindow] _autolayoutTrace];
}

You have to create a category on UIWindow in order to get this to work:

@interface UIWindow()

+ (UIWindow *)keyWindow;
- (NSString *)_autolayoutTrace;

@end

I put this category in its own header file, UIWindow_AutoLayoutDebug.h

Where ever I call [[UIWindow keyWindow] _autolayoutTrace] in my app, I import UIWindow_AutoLayoutDebug.h

I learned about calling [[UIWindow keyWindow] _autolayoutTrace] in code from the book "iOS 6 by tutorials", Volume 1, by the raywenderlich.com team. The idea of delaying the call is my own.

like image 42
bilobatum Avatar answered Nov 01 '22 04:11

bilobatum