Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation-Question #10

Open
CrEaK opened this issue Oct 5, 2012 · 2 comments
Open

Rotation-Question #10

CrEaK opened this issue Oct 5, 2012 · 2 comments
Labels

Comments

@CrEaK
Copy link

CrEaK commented Oct 5, 2012

I use a MGTableStyledBox and want full landscape support so i use this code

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orient
                                         duration:(NSTimeInterval)duration {

  BOOL portrait = UIInterfaceOrientationIsPortrait(orient);
  float width = portrait ? IPHONE_PORTRAIT_WIDTH : IPHONE_LANDSCAPE_WIDTH;

  [scroller setSize:(CGSize){width, self.view.frame.size.heigth}];

  // apply to each line in boxes
  for (MGTableStyledBox *box in scroller.boxes) {
    for (MGLine *line in box.topLines) {
        if(line.size.heigth == 44){
            line.setSize((CGSize){width, 44});
        }
    }
  }

  // relayout the sections
  [self.scroller layoutWithSpeed:duration completion:nil];
}

It works perfectly, but there are some multiLine MGLine's. They are simply ignored because their height isn't 44 sure, but how can i resize them to fit the landscape size?

Maybe you have an idea?

thanks a lot!

@sobri909
Copy link
Owner

sobri909 commented Oct 5, 2012

Possibly you could just adjust the width instead of width and height. Although the multiline rows wouldn't neatly reflow.

I think this could be classed as a bug, because multiline text isn't reflowed on each layout call, when really it should be.

As a workaround, you could regenerate the multiline rows, with something like:

// make a replacement row with new width
UILabel *label = row.leftItems[0];
MGLine *replacement = [MGLine multilineWithText:label.text 
        font:row.font width:newWidth padding:row.padding];
replacement.replacementFor = row;

// replace old row with new
int i = [self.scroller.boxes indexOfObject:row];
[self.scroller.boxes replaceObjectAtIndex:i withObject:replacement];

@CrEaK
Copy link
Author

CrEaK commented Oct 5, 2012

I figured out another way by my self. I use this code to regenerate just the label

UILabel *label = (UILabel *) [line.leftItems objectAtIndex:0];
                    CGFloat innerWidth = sizeWidth - line.padding.left - line.padding.right;
                    CGSize textSize = [label.text sizeWithFont:label.font
                                             constrainedToSize:CGSizeMake(innerWidth, FLT_MAX)];
                    label.size = (CGSize){innerWidth, textSize.height};
                    [line.leftItems replaceObjectAtIndex:0 withObject:label];
                    [line setSize:(CGSize){sizeWidth, textSize.height+line.padding.top+line.padding.bottom}];

But i found another Bug. When the orientation changed all underLines stays the same width and not resizes like the box and the lines.

thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants