bringSubviewToFront + setFrame doesn't work

982 Views Asked by At

I'm trying to bring a view to front and later set the frame from this view.

But the position doesn't change. If I comment the line [viewGeral bringSubviewToFront:viewSearchPp]; and set the viewSearchPp's frame. It works

 [viewGeral bringSubviewToFront:viewSearchPp];
   [viewSearchPp setFrame:CGRectMake(viewSearchPp.frame.origin.x, viewSearchPp.frame.origin.y + 100, viewSearchPp.frame.size.width, viewSearchPp.frame.size.height - 100)];
2

There are 2 best solutions below

0
Prashanth Rajagopalan On

It should not be bringSubviewToFront and after that setFrame, it should be setFrame and after that bringSubviewToFront.

It should be like

[viewSearchPp setFrame:CGRectMake(viewSearchPp.frame.origin.x, viewSearchPp.frame.origin.y + 100, viewSearchPp.frame.size.width, viewSearchPp.frame.size.height - 100)];

[viewGeral bringSubviewToFront:viewSearchPp];
0
dana0550 On

If you are adding viewSearchPp as a subView of viewGeral the issue could be that you are using the frame property instead of bounds. Try this:

[viewGeral bringSubviewToFront:viewSearchPp];
[viewSearchPp setFrame:CGRectMake(viewSearchPp.bounds.origin.x,
                                  viewSearchPp.bounds.origin.y + 100,
                                  viewSearchPp.bounds.size.width,
                                  viewSearchPp.bounds.size.height - 100)];

Let me know if this works.