0

I am trying to setup a side/slide menu but all the examples I find has a fixed width so when it comes to hide/show the menu they are playing with a -/+ value for the width constraint.

I wanted to set the width with a percentage ratio so I've chosen to define the width constraint as constant = 0 and multiplier = 0.4

I'm new to xcode/iOS so what is the way to show/hide the menu when you have variable width depending on the screen size?

Do I over complicate the problem? Should I stick with fixed width?

narb
  • 958
  • 1
  • 13
  • 39

1 Answers1

1

It's simple just do the same as the first case

show

 self.menuWidthCon.constant = 0

Hide

 self.menuWidthCon.constant = -1 * (self.view.bounds.size.width) * 0.3

Edit:

put the code in , make sure sideMenuConstraint is hooked properly to interface builder constraint

  override func viewDidLayoutSubviews
 {
     // MenuScrollView.contentSize.height = 1000

     if(once)
     {

         once = false
        sideMenuConstraint.constant = -1 * (self.view.bounds.size.width) * 0.45
       self.layoutIfNeeded()
     }

 }
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • That was easy :) Thanks. How do you do to size the buttons' font of the menu? – narb Jan 19 '18 at 17:28
  • say that the menu is full screen and you decided to give all buttons font 20 then what will be font when menu width is half screen so it will be 10 , with a calculation like that you can decide what to give them , sure may be there a simple deviation to add as the ratio between them may be not 1:1 – Shehata Gamal Jan 19 '18 at 17:34
  • 1
    I need to think more about it and I'll shoot a specific Q. Thanks! – narb Jan 19 '18 at 17:39
  • I have a crash :) if you have 2' take a look at my new edit. – narb Jan 19 '18 at 18:24
  • info updated. if it's not obvious, don't worry: I'll redo with fixed width. The xcode model is probably powerful but a real headache. – narb Jan 19 '18 at 20:03
  • fixed width works fine. I can't say this is the issue. I'll redo the config from scratch. – narb Jan 19 '18 at 20:49
  • 1
    re-build all. it works now. update now: sideMenuConstraint.constant = -190 was enough to close the menu. I think that as long as the minus factor is sufficient it's all good. thanks. – narb Jan 19 '18 at 21:35
  • 1
    I rewind: it's better to use your recommendations otherwise you get debug's warnings. Thanks again! – narb Jan 20 '18 at 08:11