0

I've got a view that I'm wanting to have in a specific area of the screen based on a value.

I'm trying to keep the view's location the same when a user comes back to the screen after leaving, so I'm passing around a variable of "currentSearch" , and in viewDidAppear I'm checking that value and trying to set the location accordingly.

if currentSearch == "new" {

        self.menuBar.center.x = self.new.center.x
    } else ...... //checking my other variables and doing relative location moves.

I set a breakpoint and it's going into this code and getting to the center.x bit, but the view isn't moving.

I tried animating it with a duration of 0 or .1, the view didn't move. I also tried something I saw someone else mention that looked like

  let f = menuBar.frame
    let menubar.center.x = self.new.center.x
    let menuBar.frame = f

that also did not work.

Any ideas why the view is just staying at where it's set in the storyboard?

KSR
  • 1,699
  • 15
  • 22
user6820041
  • 1,213
  • 2
  • 13
  • 29
  • May caused by Autolayout. Try setup your view in `viewDidLayoutSubviews` – zc246 Sep 12 '16 at 08:38
  • Its because of Auto layout, in auto layout every time you add or remove any view from view hierarchy or update the viewWill and viewDidlayoutSubViews method gets called and it will reposition all the views on the position as on storyboard. I have faced same problem as you are facing see http://stackoverflow.com/questions/35883784/view-on-screen-resizing-and-repositioning-itself-when-new-view-is-added-into-hie. You should set the frame in the viewDidLayoutSubViews method. – Bharat Modi Sep 12 '16 at 08:45
  • worked like a charm, thanks guys – user6820041 Sep 12 '16 at 08:54

0 Answers0