10

I have my views designed in the storyboard. When I slide out the menu, the rear view does not automatically resize to the width of the device.

How can i set the width of the view so that it matches up with the width defined by self.revealViewController().rearViewRevealWidth?

thanks

Ant
  • 747
  • 1
  • 8
  • 19

6 Answers6

9
class SideMenuViewController: UITableViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    self.revealViewController().rearViewRevealWidth = self.view.frame.width - 64
  }

}

It works for me!

Bryan Lin
  • 101
  • 1
  • 2
6

What I think Ant was looking for is the same I was trying to do when I stumbled upon this question: to make the rear view controller the size of the rear view width (in my case, I wanted this to happen since I had UI elements that had to be centered in the rear view). This worked for me:

override func viewDidAppear(_ animated: Bool) {
        self.view.frame.size.width = self.revealViewController().rearViewRevealWidth
    }

It went from this:

enter image description here

to this:

enter image description here

Iris
  • 291
  • 5
  • 10
4

On your menu bar view controller paste below line on viewdidload method

Objective C

    self.revealViewController.rearViewRevealWidth = self.view.frame.size.width-100;

Swift

self.revealViewController().rearViewRevealWidth = self.view.frame.width-100

code working fine on all screen.

abdul sathar
  • 2,395
  • 2
  • 28
  • 38
2

Add this code into Menu Controller

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    self.view.frame.size.width = self.revealViewController().rearViewRevealWidth
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    self.view.frame.size.width = self.revealViewController().rearViewRevealWidth
}

It can work with any menu. Hope this help!

lee5783
  • 434
  • 4
  • 12
2

Just set rearViewRevealOverdraw to 0 right after you set reveal width property. for an example,

self.revealViewController().rearViewRevealWidth = 300 //put the width you need   
self.revealViewController().rearViewRevealOverdraw = 0
Hanushka Suren
  • 723
  • 3
  • 10
  • 32
0

I wrote di swift 3 statements in the viewDidLoad of the my MasterController, where I programmatically configure SWRevealViewController (FrontController and RearController) and assign SWRevealViewController() to UIApplication.shared.delegate!.window?.rootViewController, but it it would work also in the viewDidLoad of your initial UIViewController

let revealController = SWRevealViewController()

// settings to show full screen menu

// set width menu to screen size 
revealController.rearViewRevealWidth = self.view.frame.width 
// hide totally shadow 
revealController.frontViewShadowOffset = CGSize.zero 
revealController.frontViewShadowOpacity = 0 

// optional settings

// no overdraw when dragging
revealController.rearViewRevealOverdraw = 0

// no displacement when animating or dragging the content
revealController.rearViewRevealDisplacement = 0
Beppex
  • 123
  • 1
  • 6