Hi Forum,
I spent a lot of time trying understand the method - (void)layoutSubviews, and I think i have it down however there is NO WAY to step through layoutSubview and go step by step, even with break points it seems like it gets called at the very last step. I do know that somehow somewhere addSuview does invoke it. So here is my question. I have a method which creates and adds a bunch of views to other views below
and here is the layouSubviews method
in the first method as we can see activityLabel is added to borderView, and in the layoutSubviews method in the "calculate position of label" section we see that a call to the activityLabel frame is made. Again it is very difficult to see exactly at what point it gets called, so my question is
1. is the layoutSubviews method smart enough to know that boarderview is activityLabels superview because of
?? because from what I see layoutSubviews gets called once...and not after every "addSubview"
I spent a lot of time trying understand the method - (void)layoutSubviews, and I think i have it down however there is NO WAY to step through layoutSubview and go step by step, even with break points it seems like it gets called at the very last step. I do know that somehow somewhere addSuview does invoke it. So here is my question. I have a method which creates and adds a bunch of views to other views below
Code:
if (!(self = [super initWithFrame:CGRectZero]))
return nil;
// Allow subclasses to change the view to which to add the activity view (e.g. to cover the keyboard):
self.originalView = addToView;
addToView = [self viewForView:addToView];
// Configure this view (the background) and its subviews:
[self setupBackground];
self.labelWidth = aLabelWidth;
self.borderView = [self makeBorderView];
self.activityIndicator = [self makeActivityIndicator];
self.activityLabel = [self makeActivityLabelWithText:labelText];
// Assemble the subviews:
[addToView addSubview:self];
[self addSubview:self.borderView];
[self.borderView addSubview:self.activityIndicator];
[self.borderView addSubview:self.activityLabel];
// Animate the view in, if appropriate:
[self animateShow];
and here is the layouSubviews method
Code:
- (void)layoutSubviews;
{
self.frame = [self enclosingFrame];
// If we're animating a transform, don't lay out now, as can't use the frame property when transforming:
if (!CGAffineTransformIsIdentity(self.borderView.transform))
return;
CGSize textSize = [self.activityLabel.text sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
// Use the fixed width if one is specified:
if (self.labelWidth > 10)
textSize.width = self.labelWidth;
NSLog(@"self.activityLabel.frame is %@",NSStringFromCGRect(self.activityLabel.frame));
self.activityLabel.frame = CGRectMake(self.activityLabel.frame.origin.x, self.activityLabel.frame.origin.y, textSize.width, textSize.height);
// Calculate the size and position for the border view: with the indicator to the left of the label, and centered in the receiver:
CGRect borderFrame = CGRectZero;
NSLog(@"self.activityIndicator.frame is %@",NSStringFromCGRect(self.activityIndicator.frame));
borderFrame.size.width = self.activityIndicator.frame.size.width + textSize.width + 25.0;
borderFrame.size.height = self.activityIndicator.frame.size.height + 10.0;
borderFrame.origin.x = floor(0.5 * (self.frame.size.width - borderFrame.size.width));
borderFrame.origin.y = floor(0.5 * (self.frame.size.height - borderFrame.size.height - 20.0));
self.borderView.frame = borderFrame;
// Calculate the position of the indicator: vertically centered and at the left of the border view:
CGRect indicatorFrame = self.activityIndicator.frame;
indicatorFrame.origin.x = 10.0;
indicatorFrame.origin.y = 0.5 * (borderFrame.size.height - indicatorFrame.size.height);
self.activityIndicator.frame = indicatorFrame;
// Calculate the position of the label: vertically centered and at the right of the border view:
CGRect labelFrame = self.activityLabel.frame;
labelFrame.origin.x = borderFrame.size.width - labelFrame.size.width - 10.0;
labelFrame.origin.y = floor(0.5 * (borderFrame.size.height - labelFrame.size.height));
self.activityLabel.frame = labelFrame;
}
in the first method as we can see activityLabel is added to borderView, and in the layoutSubviews method in the "calculate position of label" section we see that a call to the activityLabel frame is made. Again it is very difficult to see exactly at what point it gets called, so my question is
1. is the layoutSubviews method smart enough to know that boarderview is activityLabels superview because of
Code:
[self.borderView addSubview:self.activityIndicator];