I must be missing something terribly obvious here, but this has been an issue that's been frustrating me for DAYS.
In an iOS project on xcode 4.5, I've got several labels in a XIB, one on top of the other, in a UIScrollView
that occupies a UIView
. Each label is as wide as the view, and each is about 20 px above the next. On occasion, one of the labels doesn't have any information, so it gets set to invisible, and the labels below it are supposed to move up to occupy the blank space.
The problem is, if autolayout is checked "off" on the view, the labels move up exactly as they should, though the UIScrollView
no longer scrolls. If it is on, the labels do not move at all, no matter what.
Here is the code... I basically just use a quick function to move each label up by the height of the invisible label.
[self moveObjectBy: self.festNameLabel moveByY:-(yearsLabel.frame.size.height-2)];
// this just quickly moves a label.
- (void)moveObjectBy:(UIView *)lbl moveByY:(int)byHeight {
CGRect newFrame = lbl.frame;
NSLog(@"%f, %d", newFrame.origin.y, byHeight);
newFrame.origin.y += byHeight; //yearsLabel.frame.size.height;
lbl.frame = newFrame;
}
When it's run, the NSLog
shows it's Y has moved, but it doesn't move on the screen. I'm sure it has to do with the vertical space constraint, but it won't let me delete the constraint, and it won't let me change it to anything other than space from the top of the view. Like I said, I'm sure I'm missing something, but I've exhausted everything I know to do...