SwiftUI Slideoutmenu - Sample Project for slideout menu

Overview

SwiftUI_Slideoutmenu

This is a sample code project for a slideout menu.

Simulator.Screen.Recording.-.iPhone.13.-.2022-02-13.at.09.48.29.mp4

How to Implement

  1. Copy over the Model, Views, & HelperViews files to your project.
  2. Add SlideOutMenuView(showMenu: $showMenu) to your mainview within a ZStack as an if statement.

Example:

if showMenu {
  SlideOutMenuView(showMenu: $showMenu)
    .shadow(color: Color("nord2").opacity(0.5), radius: 5, x: 0, y: 0)
    .transition(.opacity)
    .animation(.easeInOut, value: showMenu)
  }
  1. Add the AnimationModifier and offset to your view.

Example:

VStack {
  YourView()
}
.modifier(AnimationModifier(showMenu: $showMenu, animationAmount: $animationAmount))
.offset(x: offset.width)

Getting Started Code

VStack {
  YourView()
}
.modifier(AnimationModifier(showMenu: $showMenu, animationAmount: $animationAmount))
.onTapGesture {
    withAnimation {
        showMenu.toggle()
    }
}
.offset(x: offset.width)
.disabled(showMenu ? true : false)
if showMenu {
    SlideOutMenuView(showMenu: $showMenu)
        .shadow(color: Color("nord2").opacity(0.5), radius: 5, x: 0, y: 0)
        .transition(.opacity)
        .animation(.easeInOut, value: showMenu)
}

Updating the Menu

  1. Update MenuItems with your content
  2. Update the switch statement within SlideOutMenuView.swift

Example:

.onTapGesture {
    switch item.id {
    case 0:
        showSomeSheet1 = true
    case 1:
        showSomeSheet2 = true
    default:
        showSomeSheet3 = true
    }
}
  1. Add the neccesary sheets needed. There is a starter sheet located within SlideOutMenuView.swift.

Calling the Slideout Menu

You can call the menu by utilzing a Bool State, in the code example I used showMenu and is triggered by swipping and a toolbar button.

Code Examples

Button:

.toolbar {
    ToolbarItem(placement: .cancellationAction) {
        Button(action: {
            withAnimation(.spring()) {
                showMenu = true
            }
        }) {
            Image(systemName: "gearshape.fill")
        }
    }
}

Swipe Gesture:

.gesture(DragGesture()
                .onChanged { gesture in
        // increase startLocation to increase edge detection
        if gesture.startLocation.x < CGFloat(50.0) {
            withAnimation {
                offset = gesture.translation
            }
        }
    }.onEnded{ value in
        if offset.width > 115 {
            withAnimation(.spring()) {
                showMenu = true
                offset = .zero
            }
        } else {
            withAnimation(.spring()) {
                offset = .zero
            }
        }
    })

Customizing

Menu Options

MenuItemModel contains the slideout menu options. You could create another model for additonal options near the the top of the menu.

Animation Modifier

I created a custom modifier AnimationModifier to reduce code. This has the bulk of the 3d modifiers to animate the view in ContentView.

Gesture Control

To increase or decrease edge detection update if gesture.startLocation.x < CGFloat(50.0). If you want to adjust how much a user needs to swipe you'll need to adjust if offset.width > 115 in ContentView.swift

Presenting Sheets

The sheets are located inwithin SlideOutMenuView.swift and I have added one sheet as an example. You could also swap out a sheet for a fullScreenCover.

Menu Size

Within SlideOutMenuView.swift you can update the frame size located at .frame(width: geo.size.width / 1.75).

Other Notes

There is a .disabled modifier to disable ContentView when the menu appears otherwise the user could experience some weird behaviors if ContentView is still active.

Feel free to email me with any questions [email protected]

You might also like...
Easily create dragabble menu with SwiftUI
Easily create dragabble menu with SwiftUI

SwiftUIDragMenu Easily create dragabble menu The gifs are not very good quality. Content is fluid. Sorry for this :( How to install this package Open

A simple customizable side menu written in SwiftUI.
A simple customizable side menu written in SwiftUI.

NSideMenu Description A simple customizable side menu written in SwiftUI. Give a Star! ⭐ Feel free to request an issue on github if you find bugs or r

A custom SwiftUI modifier to present an ActionSheet or a Popover menu
A custom SwiftUI modifier to present an ActionSheet or a Popover menu

ActionOver A custom SwiftUI modifier to present an Action Sheet on iPhone and a Popover on iPad and Mac. iPhone Preview iPad Preview Mac Preview Featu

CatalystMenuBarStatusWindow - A method of presenting UIKit (or Catalyst-specific SwiftUI) content from the status menu area on macOS Slide Menu (Drawer) in Swift
Slide Menu (Drawer) in Swift

AKSwiftSlideMenu Slide Menu (Drawer) in Swift 5.0 Why to use a library everytime? Let's create our own Slide Menu in Swift 5.0 I have uploaded a video

⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion
⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion

CIRCLE MENU Simple, elegant UI menu with a circular layout and material design animations We specialize in the designing and coding of custom UI for M

A simple side menu for iOS written in Swift.
A simple side menu for iOS written in Swift.

ENSwiftSideMenu A lightweight flyover side menu component for iOS with the UIDynamic's bouncing animation, UIGestures and UIBlurEffect. Allows you to

Menu with a circular layout based on Macaw
Menu with a circular layout based on Macaw

FanMenu Easily customizable floating circle menu created with Macaw We are a development agency building phenomenal apps. Usage Create UIView in your

Our Guillotine Menu Transitioning Animation implemented in Swift reminds a bit of a notorious killing machine.
Our Guillotine Menu Transitioning Animation implemented in Swift reminds a bit of a notorious killing machine.

GuillotineMenu.swift Inspired by this project on Dribbble Also, read how it was done in our blog Requirements iOS 8.0+ Xcode 10 Swift 5.0 (v 4.1+) Swi

Owner
Rob Evans
👋 Thanks for stopping by! 👨🏼‍💻 Self taught iOS developer.
Rob Evans
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

Hossam Ghareeb 84 Feb 4, 2022
A Slide Menu, written in Swift, inspired by Slide Menu Material Design

Swift-Slide-Menu (Material Design Inspired) A Slide Menu, written in Swift 2, inspired by Navigation Drawer on Material Design (inspired by Google Mat

Boisney Philippe 90 Oct 17, 2020
Slide-Menu - A Simple Slide Menu With Swift

Slide Menu!! Весь интерфейс создан через код

Kirill 0 Jan 8, 2022
Swift-sidebar-menu-example - Create amazing sidebar menu with animation using swift

 SWIFT SIDEBAR MENU EXAMPLE In this project I create a awesome side bar menu fo

Paolo Prodossimo Lopes 4 Jul 25, 2022
Hamburger Menu Button - A hamburger menu button with full customization

Hamburger Menu Button A hamburger menu button with full customization. Inspired by VinhLe's idea on the Dribble How to use it You can config the looks

Toan Nguyen 114 Jun 12, 2022
Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.

▤ SideMenu If you like SideMenu, give it a ★ at the top right of this page. SideMenu needs your help! If you're a skilled iOS developer and want to he

Jon Kent 5.4k Dec 29, 2022
Restaurant Menu Project - Trio.dev Code Challenge

Restaurant Menu Project - Trio.dev Code Challenge Description Get ready! You'll be creating a screen that fetches data from a restaurant API and displ

null 0 Dec 27, 2021
adb-tools-mac is a macOS menu bar app written in SwiftUI for common adb tools.

adb-tools-mac is a macOS menu bar app written in SwiftUI for common adb tools.

Naman Dwivedi 930 Jan 2, 2023
Ambar is a macOS Menu Bar app built with SwiftUI.

Ambar Ambar is a macOS Menu Bar app built with SwiftUI. It is a template project which means that it can be used as a starting point for a new Menu Ba

null 16 Nov 14, 2022
An easy way to use `canPerformAction` for context menu in SwiftUI.

Use canPerformAction for TextField/Editor in SwiftUI You know how a TextField displays a set of context menu? It doesn't matter if it's UIKit or Swift

StuFF mc 5 Dec 18, 2021