简体   繁体   中英

iPad App Navigation with SlideView - change size of UIView?

i want to create a slide out menu which has a normal width of about 50 pixels, and if the user press the expand button i will also show the labels for the button.

Like in this example:

示例菜单

What is the correct way to create such a menu? I though about using 2 views and set the size of contentview to width-50pixels.

But i am unable to change the frame of my UIView in the ViewDidLoad function. (this is an example)

override func viewDidLoad() {

    super.viewDidLoad()

    self.view.frame = CGRect(x:50, y:0, width:974, height:768)

    sidebarIsOpen = false
}

And if the user click on the expand Button

@IBAction func expandButtonClicked(sender : AnyObject) {

    var x = self.sidebarIsOpen! ? 50 : 300
    UIView.animateWithDuration(0.2, animations: {
        self.view.frame = CGRect(x:x, y:0, width:300, height:768)
        }, completion: { _ in
            self.sidebarIsOpen = !(self.sidebarIsOpen!)
        })
}

If i click the button again, everything is fine. But on ViewDidLoad i am unable to move the contentview to right.

Thanks in advance

Ill found already the solution by myself.

Created 2 views and animate the "contentview" on button click.

@IBOutlet weak var menuView: UIView!

@IBAction func toggleMenuButton(sender: UIBarButtonItem) {

    var x = self.sidebarIsOpen! ? 50 : 200

    UIView.animateWithDuration(0.2, animations: {
        self.contentView.frame = CGRect(x:x, y:0, width:974, height:768)
        }, completion: { _ in
            self.sidebarIsOpen = !(self.sidebarIsOpen!)
        })

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM