I am struggling with Autolayout (using it for the first time in a new app).
Following situation:
- Storyboard
- iPad
- Autolayout enabled
In one Popover I need to re-layout 8 buttons programmatically according to user-selection. This works fine until the moment where the buttons must be rotated by 180° (to be viewed upside down, which is an app feature).
As soon as I add the code for the rotation, the relayout does not work anymore. I don't understand why I can change the position of the buttons (like Case 2), but then, when rotating it doesnt work anymore.
Case 1:
BUTTON 0 | BUTTON 1 | BUTTON 2 | BUTTON 3
BUTTON 4 | BUTTON 5 | BUTTON 6 | BUTTON 7
Case 2:
BUTTON 7 | BUTTON 6 | BUTTON 5 | BUTTON 4
BUTTON 3 | BUTTON 2 | BUTTON 1 | BUTTON 1
(all buttons rotated 180°, i.e. flipped upside down)
Once AutoLayout is switched off, it works like a charm. The problem is that as soon as I turn off AutoLayout the rest of the App is completely screwed up.
It would be great if somebody could help me understand this problem.
The code is in viewDidAppear
for (UIButton *button in self.allButtons) {
if (button.tag == i) {
button.transform = CGAffineTransformMakeRotation(M_PI);
button.frame = CGRectMake((300 - (100 * currentButtonPosition)) + offsetWidthButton, offsetHeightButton, 100, 100);
NSLog(@"Button Tag Nr: %d\nFrame:\nX=%f\nY=%f\nW=%f\nH=%f",button.tag, button.frame.origin.x, button.frame.origin.y, button.frame.size.width, button.frame.size.height);
}
}
The frame coordinates for the buttons are all correct in the NSLog output. I guess somehow the button.transform screws up the .frame = CGRectMake part, but why I don't understand and am looking forward for your help or guidance where to continue to study the mysterious autoLayout.
Hope the explanation is understandable :-)
Thanks and have a nice day Ronnie