adit
adit

Reputation: 33674

insertSubviewBelow not inserting at the correct frame Y offset

I have a UIViewController view that I wanted to insert below a subview:

[self.view insertSubview:ntVC_.view belowSubview:shareView_];

The shareView frame Y is 959 and it's height is 44. So when doing this shouldn't ntVC frame Y be at 1004? However it's at 925 now. Any idea?

Upvotes: 1

Views: 130

Answers (1)

Paul.s
Paul.s

Reputation: 38728

The method insertSubview:belowSubview: refers to the view stack not a view's coordinates.

You need to do the calculation of where to position the view yourself.

+-------+         +-------+
|       |         |       |
|  A +-------+    |  A    |----+
|    |       |    |       |    |
+----|  B    |    +-------+    |
     |       |         |   B   |
     +-------+         +-------+

In terms of the view stack

  • In the example on the left A is below B
  • In the example on the right A is above B

Upvotes: 7

Related Questions