Questions tagged [layoutsubviews]

layoutSubviews is a method that is called automatically during view size changes. It can be used by a custom view to perform additional manual changes above and beyond any autoresizing behaviours

This method is called automatically and should not be called directly. UIKit will call it automatically whenever a view size changes. This could be as a result of resizing due to orientation changes. For example when the user rotates the iOS device to portrait or landscape mode.

In the custom view that implementslayoutSubviews, any view changes in addition to the autoresizing behaviours should be applied.

For further information please refer to the View Programming Guide for iOS. See the section on "Tweaking the Layout of Your Views Manually".

See also the UIView Class Reference.

145 questions
274
votes
8 answers

When is layoutSubviews called?

I have a custom view that's not getting layoutSubview messages during animation. I have a view that fills the screen. It has a custom subview at the bottom of the screen that correctly resizes in Interface Builder if I change the height of the nav…
Steve Weller
  • 4,409
  • 4
  • 20
  • 30
55
votes
4 answers

How to force layoutSubviews of UIView?

I have a custom UIView which has a dedicated, manually set frame for portrait and landscape orientation because autoresizingMasks just don't work in my case. I set this frame in: - (void)viewWillAppear:(BOOL)animated And it works as expected. My…
myell0w
  • 2,120
  • 1
  • 20
  • 25
28
votes
1 answer

UIView/CALayer: Transform triggers layoutSubviews in superview

When changing some of the properties for UIView it triggers layoutSubviews in the superview. I can not find any statements about this in the docs. These properties triggers layout in superview and self frame bounds These properties triggers…
hfossli
  • 21,612
  • 9
  • 111
  • 127
16
votes
4 answers

layoutSubviews during an animation?

I have a UIView with a bunch of subviews, all positioned using layoutSubviews. When the view is resized, the relative positions all change. I'd like these re-calculations to happen during an animated resize (using +[UIView beginAnimations:] calls).…
Ben Gottlieb
  • 84,498
  • 22
  • 171
  • 170
16
votes
1 answer

where to create autolayout constraints for subclassed uitableviewcell?

I am trying to use autolayout for a uitableviewcell subclass I am creating and I would appreciate some advice on what method to put the layout constraint creation code. I have been searching around and all the information I find talks about adding…
Ty Newton
  • 193
  • 1
  • 1
  • 7
12
votes
2 answers

iOS: determine when all children have had layoutSubviews called

it appears that viewDidLayoutSubviews is called immediately after layoutSubviews is called on a view, before layoutSubviews is called on the subviews of that view. Is there any way of knowing when layoutSubviews has been called on a view and all of…
Thayne
  • 5,931
  • 1
  • 33
  • 55
10
votes
0 answers

iOS OpenGL Catch-22: OpenGL background rules and "app snapshot" for App Switcher

Like many developers, I have an app that uses OpenGL via a UIView subclass whose layerClass: method returns [CAEAGLLayer class]. Note I am not using GLKit or GLKView or GLKViewController When I click Home to put the app into the background, after…
Louis Semprini
  • 2,495
  • 25
  • 26
7
votes
1 answer

Fatal Exception: NSInternalInconsistencyException how to find offending code?

I've this random crash in live app. I know how to fix it. I want to know how to find out offending code as the crashlytics log doesn't show any code in my app. Is this crashlytics crash? Since it's random crash I can't debug it. Any pointer to find…
Raymond
  • 794
  • 3
  • 18
7
votes
3 answers

Xcode6, iOS8 and (void)layoutSubviews

I have custom UILabel which works fine on iOS6 and iOS7. But on iOS8 this label's (void)layoutSubviews method never get called. I create this label with initWithFrame, so this method should be called - and it's called on another iOS versions. What…
Maria
  • 745
  • 11
  • 28
7
votes
9 answers

Cannot change frame of a UILabel in a UITableViewCell when first appearing (using Autolayout)

I have a prototype cell inside my UITableView which contains a UILabel. I want to dynamically change the size of the label (and the cell) depending on the size of the text in the label. I create the prototype cell in cellForRowAtIndexPath like…
theDuncs
  • 4,211
  • 4
  • 35
  • 58
6
votes
1 answer

Is there any way that I can manipulate the parent view controller so that the subviews will be underneath the UIPageControl?

I'm implementing horizontal scrolling in an app by making use of an UIPageViewController which I set the navigation property to 'Horizontal' and the Transistion Style to 'scroll'. Everything works fine, I can add some subviews that are presented…
6
votes
1 answer

layoutSubviews called twice when rotating

When my main view rotates I want to re-arrange the sub views, so in my ViewController, I override willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration and set the frames of the subViews in…
Bbx
  • 2,622
  • 3
  • 18
  • 27
5
votes
1 answer

ios UITableViewCell programmatically create in drawRect vs layoutSubviews

I've been trying to create complex UITableViewCell through Autolayout but it is giving a huge performance lag while scrolling, So I decided to go for frame-based i.e programmatically. The complexity of cell layout is like Facebook cards where every…
Mukesh
  • 3,564
  • 1
  • 12
  • 30
4
votes
1 answer

Why layoutIfNeeded() allows to perform animation when updating constraints?

I have two states of UIView: I have animation between them using @IBaction for button: @IBAction func tapped(sender: UIButton) { flag = !flag UIView.animateWithDuration(1.0) { if self.flag { …
Bartłomiej Semańczyk
  • 52,820
  • 43
  • 206
  • 318
4
votes
1 answer

layoutSubviews in infinite loop on iOS 8 GM

My app subclasses a UITableViewCell and implements layoutSubviews to modify the cell's contentView's width, like so: - (void)layoutSubviews { [super layoutSubviews]; // position subviews... CGRect frame = [[self contentView] frame]; …
Steveo
  • 2,050
  • 1
  • 19
  • 33
1
2 3
9 10