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.

149 questions
1
vote
1 answer

Why does UITableViewCell.layoutSubviews() have frame.width as 600 (universal storyboard width) and not 320 (specific iPhone device)?

I have a project with a Universal storyboard (screen size: 600 x 600) containing a class that overrides UITableViewCell: class MyTableCell: UITableViewCell { ... } Rather than utilising a prototype cell, the UITableView that displays this cell…
Joseph Beuys' Mum
  • 2,395
  • 2
  • 24
  • 50
1
vote
1 answer

Why layoutSubviews called twice?

I have subClass an UIView and override the layoutSubviews method. When I called this subClass in my viewController,and add it to the controller's view,I found that "layoutSubviews" function have been called twice. coverFlowView =…
Eric
  • 99
  • 1
  • 7
1
vote
2 answers

Issue while using viewDidLayoutSubviews

I have heard that viewDidLayoutSubviews is the best place to alter the layout when we have used constraints. So I jumped to viewDidLayoutSubviews I have created three UIViews and SubViewed them on SuperView. I am not mentioning the code for frame…
Rahul
  • 5,594
  • 7
  • 38
  • 92
1
vote
0 answers

UIDynamicAnimator with layoutSubviews laggy

I try to implement side bar menu. I already have done it with standard UIView animations, but now i want to add some feelings to it. I decided to use UIViewDynamics. I noticed that, after main view frame changed, it is necessary to recreate…
1
vote
2 answers

UITableViewCell : cell shrinks on reload data call

I am trying to make a chat application.I populate the chat bubbles from nib. But whenever I add a new message to the array and call reloadData method, the cells above it shrink. Here is my code for UITableView cellForRowAtIndexPath: …
1
vote
1 answer

UIView window is nil while being visible

I have a UIView and when I tried updating its subviews alphas and frames I could't succeed. I checked the views window property and found its nil. What should I do fix it? I have already tried all the: -layoutSubviews, -layoutSublayers,…
ashvardanian
  • 424
  • 1
  • 6
  • 17
1
vote
2 answers

How to trigger tableView's heightForRowAtIndexPath after viewDidLayoutSubviews get called?

tableViewCell contains viewController which height is calculated after tableView finish laying out views. So I need to trigger tableView to request again height of rows by calling heightForRowAtIndexPath method. I have tried setNeedsLayout, it does…
János
  • 32,867
  • 38
  • 193
  • 353
1
vote
1 answer

How to update constraint after layout subviews?

I know that rendering a view has the following 3 steps in this order: updating constraints layout views (here is where we get calculation of frames) display Now my question if I modify the custom buttons height, and that button has constraint…
János
  • 32,867
  • 38
  • 193
  • 353
1
vote
1 answer

What is the advantage to set cell subviews frame in layoutSubviews method vs in cellForRowAtIndexPath method?

I am just thinking what is the advantage to set up frames, coordinates / sizes in layoutSubviews in case UITableViewCell is subclassed vs directly when cell is created in cellForRowAtIndexPath? As I see if autoresizingmask properly do his job to set…
János
  • 32,867
  • 38
  • 193
  • 353
1
vote
1 answer

Stop a UITableView from reloading data on orientation change

My uitableview calls reloaddata when the orientation of the device changes (makes sense, since the number of cells displayed changes, is called in layout subviews as far as I could understand from the documentation), however this is problematic for…
Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43
1
vote
0 answers

Timing child view layout with UICollectionView layout changes

I have a UICollectionView that has a custom layout that changes the sizes of its cells when the device rotates. When the layout changes the size of a cell, layoutSubviews is called on each cell. This is what I want. However layoutSubviews does…
dakamojo
  • 1,839
  • 5
  • 21
  • 35
1
vote
1 answer

How to use CAGradientLayer in layoutSubview by changing orientation

I have created a CAGradientLayer in a layoutSubview. This works, but if I change orientation it seems that the old frame doesn't disappear. - (void) layoutSubviews { CAGradientLayer *bgLayer = [GradientClass getGradient]; bgLayer.frame =…
Denis
  • 61
  • 1
  • 10
1
vote
0 answers

(UITableViewCell) Does overriding layoutSubviews compete with auto layout or storyboards?

I am making a subclass of UITableView cell. I have set the cell contentView, backgroundView, and selectedBackgroundView all to a single CGInsetRect (Of the 180.0 rowHeight set in the tableView). My first problem is when I try to assign the inset…
user
  • 3,388
  • 7
  • 33
  • 67
1
vote
1 answer

ios what is opposite of layoutSubviews

I have a view that exits in its own class, with its own xib. This view is initialized and added as a subview to my viewController view. When the view is initialized, the method layoutSubviews is called where i customize some stuff in the view. BUT…
B-Man
  • 2,209
  • 3
  • 22
  • 35
1
vote
2 answers

self.decelerating and self.dragging in UIScrollView's layoutSubviews

It appears self.decelerating and self.dragging are not reliable during an overridden layoutSubviews call. For example, they are occasionally both true, which is obviously not possible. Is there a reliable way to get whether the UIScrollView is…
Max
  • 2,760
  • 1
  • 28
  • 47