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
3
votes
1 answer

What kind of things can cause viewWillLayoutSubviews to be run in the background thread?

I have detected a rare crash in my application. The stack trace was not helpful. It is not directly related to my code: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSAttributeDictionary…
frankish
  • 6,738
  • 9
  • 49
  • 100
3
votes
1 answer

Swift - UIBezierPath Extra argument 'radius' in call

I was adapting an Objective-C Library (STKSpinnerView) to Swift and I can't solve this error: func getRadius() -> CGFloat { var r : CGRect = CGRectInset(self.bounds, self.wellThickness/2.0, self.wellThickness/2.0) var w : CGFloat =…
rulilg
  • 1,604
  • 4
  • 15
  • 19
3
votes
1 answer

IOS algorithm behind constraint & Auto Layout

i'm trying to reverse engineer the layoutSubviews function in IOS where it calculates the autosizes and contraints. Normally, if we create constraints in orders: A depends (constrained) B, B depends C, and C was inited with a fix frame, a system…
Akito Eki
  • 151
  • 2
  • 11
3
votes
0 answers

iOS recommended way of handling portrait and landscape orientation interfaces

I am working on an iPad app and want to support both portait and landscape orientation. Currently, I am seeing three ways to handle orientation: 1) Apple recommends using two view controllers…
Zhang
  • 11,549
  • 7
  • 57
  • 87
3
votes
4 answers

why isn't -layoutSubviews being called?

I'm trying to create a custom layout for some subviews. My file is a ViewController, so I have to refer to its view as self.view. The subviews are subviews of self.view. When I call [self layoutSubviews]; explicitly in viewDidLoad, it will execute…
alsuhr
  • 129
  • 2
  • 11
2
votes
1 answer

UIScrollView with custom layoutSubviews does not animate anymore

I have a subclass of UIScrollView that I'm using for images slideshow, with infinite scrolling and circular slideshow. I used to animate the transition in this way: (Because I wanted the transition to be slower) [UIView animateWithDuration:1.0 …
Avi Shukron
  • 6,088
  • 8
  • 50
  • 84
2
votes
2 answers

UIScrollView layoutSubviews behavior changes in iOS 5?

I'm working on a component that is a subclass from UIView and contains a UIScrollView. When scrolling, I noticed different behaviors depending on which SDK I build with. On iOS 4 the layoutSubviews message is send on the scroll view's superview…
AgentCorleone
  • 90
  • 1
  • 6
2
votes
1 answer

custom method in custom view for subview layout, or use of layoutSubviews/layoutIfNeeded

I have a custom UIView that is used within a UIViewController. The custom view needs some custom/programtic layout. What I'm currently doing is, from within the controller "viewDidAppear" method I'm calling a custom view method I've put in place…
Greg
  • 34,042
  • 79
  • 253
  • 454
2
votes
1 answer

IBDesignable rendered at the top left of the screen instead of their correct position

I have a custom implementation of a checkbox / radio button in Swift. The class is annotated as @IBDesignable. I implement layoutSubviews and prepareForInterfaceBuilder. This implementation is distributed in a pod that is used in several…
Carl Sarkis
  • 119
  • 6
2
votes
2 answers

Swift - TextView layoutSubviews() not called during viewWillTransition()

Does anyone know why UITextView.layoutSubviews() is not called when rotating a device to portrait mode? When rotating to landscape mode, these are…
Lena Verhoev
  • 231
  • 1
  • 3
  • 15
2
votes
1 answer

Update shadow path on device rotation change. Problem with shadow

I have a View that contains other views. ViewforShadow -> View-> bottomBlueView func setupMyView() { myView.layer.shadowColor = #colorLiteral(red: 0.2901960784, green: 0.2901960784, blue: 0.2901960784, alpha: 1) myView.layer.shadowOffset =…
ShadeToD
  • 403
  • 9
  • 22
2
votes
1 answer

UITableViewCell hides part of content after appearing on the screen with custom layoutSubviews()

I'm struggling with UITableView. As you can see in this video in third section of table view third cell isn't display correctly. That happens when I dequeue my cell like that: let cell = tableView.dequeueReusableCell(withIdentifier:…
kkiermasz
  • 464
  • 2
  • 15
2
votes
2 answers

Change background image on ipad after rotation

I show bg of my app using UIImageView. To support correct interface rotation i write layoutSubviews method. In this metod .frame property changes correctly, but when i try change image of UIImageView just like this: view = [self viewWithTag:1002]; …
lighting
  • 23
  • 1
  • 3
2
votes
2 answers

layoutsubviews only called once despite any device rotation

just what the title says: I create an empty UIView subclass and I add a subview to it, I create an empty layoutSubviews method and I add a breakpoint there. Then I build the project and the simulation stops when loading the view at that point in the…
daniel
  • 21
  • 1
  • 3
2
votes
2 answers

What is the ideal place to set edge insets of UIButton when its subview of a UITableViewCell or subview of Any other View

I have a scenario where I need to change UIEdgeInsets for UIButton which is added to the UITableViewCell, I set it in layoutSubviews but that's called a number of times, it also work's with init too but I am not sure that's really a place because…
Retro
  • 3,985
  • 2
  • 17
  • 41
1 2
3
9 10