1

If I receive a phone call while using my app, the view is bumped down a bit to make room for the call status bar at the top.

Once the call is over, the view stays in this 'altered' state. How can I force the app to re-size itself? Currently I have to kill the app and re-start.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
edhnb
  • 2,122
  • 3
  • 24
  • 38

1 Answers1

2

Do you have any custom views that override -layoutSubviews?

In my experience, this means you have a view that does custom layout using -layoutSubviews but does not call -setNeedsLayout: at the appropriate times; in general setting the frame does not force a layout (auto-layout is handled differently).

In any view that overrides -layoutSubviews, try the following:

-(void)setFrame:(CGRect)frame
{
  CGRect oldFrame = self.frame;

  // This check changes behaviour slightly:
  //   v.frame = v.frame;
  // no longer cancels animations.
  // Sometimes this works around an animation glitch.
  if (!CGRectEqualToRect(frame,oldFrame))
  {
    [super setFrame:frame];
    if (!CGSizeEqualToSize(frame.size,oldFrame.size))
    {
      // Only layout if the size changes.
      [self setNeedsLayout];
    }
  }
}

(You could do the same for -setBounds: but it's generally unnecessary since AFAIK it doesn't get called by UIKit except for UIScrollView.)

Community
  • 1
  • 1
tc.
  • 33,468
  • 5
  • 78
  • 96