How to know if Autolayout is enable and if so disable it.. No Xib or storyboard RRS feed

  • Question

  • User89739 posted

    Hi, I'm having some problems, I'm working to update an old project developed with xcode 4.6 using the latest xcode. The problem is that sometimes I need to do something like this UIButton.Frame = new RectangleF(x,y,width,height); but X and Y does not change and stays as zeros... So it should be a problem of autolayout, but I'm not using storyboard nor designer... How can i disable autolayout and have this code work?

    Monday, July 20, 2015 2:24 PM

All replies

  • User35208 posted

    Turn off "Use Auto Layout" in IB or check the "translateAutoresizingMaskIntoConstraints" property on your parent view.

    Monday, July 20, 2015 3:27 PM
  • User89739 posted

    @TedRogers I'm not using IB.... So I need to set TranslateAutoresizingMaskIntoConstraints at true on my parent view?

    Monday, July 20, 2015 3:38 PM
  • User35208 posted

    so, you are creating all views in code? You want to make sure TranslateAutoresizingMaskIntoConstraints is false. Otherwise, as the name implies, you will get constraints.

    Monday, July 20, 2015 3:44 PM
  • User89739 posted

    yes everything is in code... Mmmm.. setting it to false some elements arte positioned at the top-left of the screen..

    Monday, July 20, 2015 3:47 PM
  • User35208 posted

    you can always check to see if you have some constraints you are fighting with. Here is some sample code in objective-c:

    + (void)dumpConstraints:(UIView *)view recursively:(BOOL)recursively
        NSArray *constraints = [view constraints];
        for (NSLayoutConstraint *constraint in constraints) {
             NSLog(@"constraint = %@\n", constraint);
        if (recursively) {
            NSArray *subViews = [view subviews];
            for (UIView *subView in subViews) {
                [self dumpConstraints:subView recursively:true];
    Monday, July 20, 2015 4:03 PM
  • User89739 posted

    One question, should I set TranslateAutoresizingMaskIntoConstraints to false only in the container view or also for each element I insert in it?

    Tuesday, July 21, 2015 8:18 AM
  • User181 posted

    You should set it on each subview.

    Tuesday, July 21, 2015 2:43 PM