├── ToggleMenu.gif ├── ToggleMenuStoryboard.gif ├── MenuToggle ├── Assets.xcassets │ ├── Contents.json │ ├── Toggle.imageset │ │ ├── Toggle.png │ │ ├── Toggle@2x.png │ │ ├── Toggle@3x.png │ │ └── Contents.json │ ├── IMG_2810.imageset │ │ ├── IMG_2810.jpg │ │ └── Contents.json │ ├── Menu-100.imageset │ │ ├── Menu-100.png │ │ ├── Menu-100@2x.png │ │ ├── Menu-100@3x.png │ │ └── Contents.json │ ├── SaveMedia.imageset │ │ ├── SaveMedia.png │ │ ├── SaveMedia@2x.png │ │ ├── SaveMedia@3x.png │ │ └── Contents.json │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ViewController.swift └── ToggleMenu.swift ├── MenuToggle.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata ├── xcuserdata │ └── bragestaven.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── MenuToggle.xcscheme └── project.pbxproj └── README.md /ToggleMenu.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/ToggleMenu.gif -------------------------------------------------------------------------------- /ToggleMenuStoryboard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/ToggleMenuStoryboard.gif -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Toggle.imageset/Toggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/Toggle.imageset/Toggle.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Toggle.imageset/Toggle@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/Toggle.imageset/Toggle@2x.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Toggle.imageset/Toggle@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/Toggle.imageset/Toggle@3x.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/IMG_2810.imageset/IMG_2810.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/IMG_2810.imageset/IMG_2810.jpg -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Menu-100.imageset/Menu-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/Menu-100.imageset/Menu-100.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Menu-100.imageset/Menu-100@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/Menu-100.imageset/Menu-100@2x.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Menu-100.imageset/Menu-100@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/Menu-100.imageset/Menu-100@3x.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/SaveMedia.imageset/SaveMedia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/SaveMedia.imageset/SaveMedia.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/SaveMedia.imageset/SaveMedia@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/SaveMedia.imageset/SaveMedia@2x.png -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/SaveMedia.imageset/SaveMedia@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bragegs/DropDownMenu/HEAD/MenuToggle/Assets.xcassets/SaveMedia.imageset/SaveMedia@3x.png -------------------------------------------------------------------------------- /MenuToggle.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/IMG_2810.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "IMG_2810.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Toggle.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Toggle.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "Toggle@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "Toggle@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/Menu-100.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Menu-100.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "Menu-100@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "Menu-100@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/SaveMedia.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "SaveMedia.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "SaveMedia@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "SaveMedia@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MenuToggle/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /MenuToggle.xcodeproj/xcuserdata/bragestaven.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MenuToggle.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 21BC50641CDCC40800E85CB0 16 | 17 | primary 18 | 19 | 20 | 21BC50781CDCC40800E85CB0 21 | 22 | primary 23 | 24 | 25 | 21BC50831CDCC40900E85CB0 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /MenuToggle/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /MenuToggle/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MenuToggle 4 | // 5 | // Created by Brage Staven on 06.05.2016. 6 | // Copyright © 2016 Stav1. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DropDownMenu 2 | ========= 3 | 4 | This library provides a very light drop down menu in swift. The icons used in the example project is downloaded from [icons8](https://icons8.com/). 5 | 6 |

7 | 8 | How To Use 9 | ---------- 10 | 11 | You only need the 'MenuToggle.swift', copy that to your project. 12 | 13 | ### Programatically 14 | 15 | ```Swift 16 | 17 | func addToggleMenu(){ 18 | 19 | var buttons = [UIButton]() 20 | for _ in 0..<10{ 21 | let button = UIButton() 22 | button.setImage(UIImage(named: "menuButton"), forState: .Normal) 23 | buttons.append(button) 24 | button.addTarget(self, action: #selector(darkMenuButtonPressed), forControlEvents: .TouchUpInside) 25 | } 26 | 27 | let toggleView = ToggleMenu(frame: CGRectMake((40,40, 46, 46), toggleImage: UIImage(named: "Toggle")!, menuButtons: buttons) 28 | 29 | self.view.addSubview(toggleView) 30 | } 31 | 32 | func darkMenuButtonPressed(){ 33 | print("I pressed a dark menu button") 34 | } 35 | 36 | ``` 37 | ### StoryBoard 38 | 39 |

40 | 41 | 42 | ## License 43 | 44 | The MIT License (MIT) 45 | Copyright (c) 2016 Brage G. Staven 46 | 47 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 48 | 49 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 50 | 51 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 | -------------------------------------------------------------------------------- /MenuToggle/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /MenuToggle/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // MenuToggle 4 | // 5 | // Created by Brage Staven on 06.05.2016. 6 | // Copyright © 2016 Stav1. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | // Connect the menu from the storyboard. The view must have constraints for height and width where height-constraint = width-constraint. 14 | @IBOutlet weak var theToggleMenu: ToggleMenu! 15 | 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | // Adding menubuttons to XIB toggleMenu 20 | var buttons = [UIButton]() 21 | for _ in 0..<3{ 22 | let button = UIButton() 23 | button.setImage(UIImage(named: "Toggle"), forState: .Normal) 24 | buttons.append(button) 25 | button.addTarget(self, action: #selector(darkMenuButtonPressed), forControlEvents: .TouchUpInside) 26 | } 27 | self.theToggleMenu.menuButtons = buttons 28 | } 29 | 30 | 31 | override func viewDidAppear(animated: Bool) { 32 | super.viewDidAppear(animated) 33 | addLightToggleView() 34 | addDarkToggleView() 35 | addExtraLightToggleView() 36 | } 37 | 38 | //You can add the toggleMenu programatically 39 | override func viewDidLayoutSubviews() { 40 | super.viewDidLayoutSubviews() 41 | 42 | } 43 | 44 | func addDarkToggleView(){ 45 | var buttons = [UIButton]() 46 | for _ in 0..<10{ 47 | let button = UIButton() 48 | button.setImage(UIImage(named: "SaveMedia"), forState: .Normal) 49 | buttons.append(button) 50 | button.addTarget(self, action: #selector(darkMenuButtonPressed), forControlEvents: .TouchUpInside) 51 | } 52 | 53 | let toggleView = ToggleMenu(frame: CGRectMake((self.view.bounds.width*0.33)-92,40, 46, 46), toggleImage: UIImage(named: "Toggle")!, menuButtons: buttons) 54 | 55 | self.view.addSubview(toggleView) 56 | } 57 | 58 | // Custom effect style on init: 59 | func addLightToggleView(){ 60 | var buttons = [UIButton]() 61 | for _ in 0..<6{ 62 | let button = UIButton() 63 | button.setImage(UIImage(named: "Toggle"), forState: .Normal) 64 | buttons.append(button) 65 | button.addTarget(self, action: #selector(lightMenuButtonPressed), forControlEvents: .TouchUpInside) 66 | } 67 | 68 | let toggleView = ToggleMenu(frame: CGRectMake((self.view.bounds.width*0.66)-92,40, 46, 46), toggleImage: UIImage(named: "Toggle")!, menuButtons: buttons,withEffectStyle:UIBlurEffectStyle.Light) 69 | self.view.addSubview(toggleView) 70 | } 71 | 72 | // Custom effect style change with delay: 73 | func addExtraLightToggleView(){ 74 | var buttons = [UIButton]() 75 | for _ in 0..<3{ 76 | let button = UIButton() 77 | button.setImage(UIImage(named: "Menu-100"), forState: .Normal) 78 | buttons.append(button) 79 | button.addTarget(self, action: #selector(extraLightMenuButtonPressed), forControlEvents: .TouchUpInside) 80 | } 81 | 82 | let toggleView3 = ToggleMenu(frame: CGRectMake((self.view.bounds.width*0.99)-92,40, 46, 46), toggleImage: UIImage(named: "Menu-100")!, menuButtons: buttons) 83 | self.view.addSubview(toggleView3) 84 | toggleView3.setBlurViewEffectStyle(UIBlurEffectStyle.ExtraLight,afterDelay: 0.5) 85 | } 86 | 87 | func darkMenuButtonPressed(){ 88 | print("I pressed a dark menu button") 89 | } 90 | func lightMenuButtonPressed(){ 91 | print("I pressed a light menu button") 92 | } 93 | func extraLightMenuButtonPressed(){ 94 | print("I pressed a extra-light menu button") 95 | } 96 | 97 | @IBAction func icons8pressed(sender: AnyObject) { 98 | UIApplication.sharedApplication().openURL(NSURL(string: "http://www.icons8.com")!) 99 | } 100 | 101 | } 102 | 103 | -------------------------------------------------------------------------------- /MenuToggle.xcodeproj/xcuserdata/bragestaven.xcuserdatad/xcschemes/MenuToggle.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /MenuToggle/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /MenuToggle/ToggleMenu.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ToggleMenu.swift 3 | // 4 | // Created by Brage Staven on 06.05.2016. 5 | // Copyright © 2016 Stav1. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | class ToggleMenu: UIView { 11 | 12 | 13 | /** 14 | Used to not add the menu buttons multiple times. 15 | */ 16 | private var hasAddedButtonsToView = false 17 | /** 18 | The original height of the toggle menu. Is used to animate back to this height when untoggeling 19 | */ 20 | private var originalHeight:CGFloat! 21 | /** 22 | Do not want it to layout multiple times. 23 | */ 24 | private var hasLayedOutView=false 25 | 26 | /** 27 | The main button that toggles the menu. 28 | */ 29 | let toggleButton = UIButton() 30 | /** 31 | The menu buttons. 32 | */ 33 | var menuButtons = [UIButton]() 34 | /** 35 | The size of the buttons. Used to calculate the height of the menu. Default is 2 pixels smaller in width and height than the toggle button. 36 | */ 37 | var buttonSize:CGSize! 38 | /** 39 | The effect style of the menu background 40 | */ 41 | var blurEffectStyle:UIBlurEffectStyle? 42 | /** 43 | The blureffectView of the menu background. 44 | */ 45 | var blurEffectView:UIVisualEffectView! 46 | /** 47 | If the view is toggled or not. 48 | */ 49 | var toggled = false 50 | /** 51 | The image of the toggleButton when initialized as an IBoutlet in storyboard/XIB 52 | */ 53 | @IBInspectable var ToggleImage: UIImage? { 54 | didSet { 55 | self.toggleButton.setImage(ToggleImage, forState: .Normal) 56 | } 57 | } 58 | /** 59 | You can set the UIEffectStyle of choise in Storyboard/XIB. You have to set the strings "Dark" for dark, "Light" for light" or "ExtraLight" for extra light effect style. 60 | */ 61 | @IBInspectable var effectStyle: String? { 62 | didSet { 63 | if effectStyle != nil{ 64 | switch effectStyle!{ 65 | case "Dark": 66 | self.blurEffectStyle = UIBlurEffectStyle.Dark 67 | break; 68 | case "Light": 69 | self.blurEffectStyle = UIBlurEffectStyle.Light 70 | break; 71 | case "ExtraLight": 72 | self.blurEffectStyle = UIBlurEffectStyle.ExtraLight 73 | break; 74 | default: 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | 81 | init(frame: CGRect, toggleImage: UIImage, menuButtons: [UIButton], withEffectStyle:UIBlurEffectStyle) { 82 | self.menuButtons = menuButtons 83 | toggleButton.setImage(toggleImage, forState: .Normal) 84 | super.init(frame: frame) 85 | self.blurEffectStyle = withEffectStyle 86 | } 87 | 88 | init(frame: CGRect, toggleImage: UIImage, menuButtons: [UIButton]) { 89 | self.menuButtons = menuButtons 90 | toggleButton.setImage(toggleImage, forState: .Normal) 91 | super.init(frame: frame) 92 | } 93 | 94 | required init?(coder aDecoder: NSCoder) { 95 | super.init(coder: aDecoder) 96 | } 97 | 98 | override func layoutSubviews() { 99 | super.layoutSubviews() 100 | layoutMenu() 101 | } 102 | 103 | override func drawRect(rect: CGRect) { 104 | super.drawRect(rect) 105 | } 106 | 107 | 108 | /** 109 | Toggles or untoggles the menu. Use this to manually toggle/untoggle the view 110 | */ 111 | func togglePressed(){ 112 | if toggled{ 113 | animateUnToggle() 114 | self.toggled = false 115 | }else{ 116 | animateToggle() 117 | self.toggled = true 118 | } 119 | } 120 | 121 | /** 122 | Changing the background effect of the toggle menu after x seconds 123 | 124 | - Parameter blur(UIBlurEffectStyle): the UIBlurEffectStyle of your choise 125 | - Parameter afterDelay(Double): number of seconds before the change should occour. 126 | - Default: UIBlurEffectStyle.Dark 127 | */ 128 | 129 | func setBlurViewEffectStyle(blur:UIBlurEffectStyle, afterDelay:Double){ 130 | delay(afterDelay) { 131 | self.blurEffectView.removeFromSuperview() 132 | let blurEffect = UIBlurEffect(style: blur) 133 | let blurEffectView = UIVisualEffectView(effect: blurEffect) 134 | blurEffectView.frame = self.bounds 135 | blurEffectView.layer.cornerRadius = self.bounds.width/2 136 | blurEffectView.clipsToBounds = true 137 | blurEffectView.backgroundColor = .clearColor() 138 | blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 139 | self.blurEffectView = blurEffectView 140 | self.insertSubview(blurEffectView, atIndex: 0) 141 | } 142 | } 143 | 144 | 145 | /** 146 | Adds the toggle button and the effect view background. Default is UIBlurEffectStyle.Dark. Also removing constraints if view is set in storyboard/XIB 147 | */ 148 | private func layoutMenu(){ 149 | if !hasLayedOutView{ 150 | hasLayedOutView = true 151 | self.removeConstraints() 152 | self.backgroundColor = UIColor.clearColor() 153 | 154 | var blurEffect:UIBlurEffect! 155 | if self.blurEffectStyle == nil{ 156 | blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark) 157 | }else{ 158 | blurEffect = UIBlurEffect(style: self.blurEffectStyle!) 159 | } 160 | let blurEffectView = UIVisualEffectView(effect: blurEffect) 161 | blurEffectView.frame = self.bounds 162 | blurEffectView.layer.cornerRadius = self.bounds.width/2 163 | blurEffectView.clipsToBounds = true 164 | blurEffectView.backgroundColor = .clearColor() 165 | blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 166 | self.insertSubview(blurEffectView, atIndex: 0) 167 | self.blurEffectView = blurEffectView 168 | let padding:CGFloat = 4 169 | toggleButton.frame = CGRectMake(padding, padding, self.bounds.width-(padding*2), self.bounds.width-(padding*2)) 170 | toggleButton.addTarget(self, action: #selector(togglePressed), forControlEvents: .TouchDown) 171 | self.addSubview(toggleButton) 172 | self.buttonSize = CGSizeMake(self.toggleButton.bounds.width-2, self.toggleButton.bounds.height-2) 173 | } 174 | } 175 | 176 | /** 177 | Untoggles the menu 178 | */ 179 | private func animateUnToggle(){ 180 | let padding:CGFloat = 4 181 | UIView.animateWithDuration(0.2) { 182 | self.toggleButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)) 183 | self.toggleButton.frame = CGRectMake(padding, padding, self.originalHeight-(padding*2), self.originalHeight-(padding*2)) 184 | self.frame = CGRectMake(self.frame.minX, self.frame.minY, self.frame.width, self.originalHeight) 185 | self.layoutIfNeeded() 186 | } 187 | for i in 0..()) { 259 | dispatch_after( 260 | dispatch_time( 261 | DISPATCH_TIME_NOW, 262 | Int64(delay * Double(NSEC_PER_SEC)) 263 | ), 264 | dispatch_get_main_queue(), 265 | closure 266 | ) 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /MenuToggle.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 21448E661CDCFE0500677345 /* ToggleMenu.gif in Resources */ = {isa = PBXBuildFile; fileRef = 21448E651CDCFE0500677345 /* ToggleMenu.gif */; }; 11 | 217871E71CDDE28B00EC389F /* ToggleMenuStoryboard.gif in Resources */ = {isa = PBXBuildFile; fileRef = 217871E61CDDE28B00EC389F /* ToggleMenuStoryboard.gif */; }; 12 | 21BC50691CDCC40800E85CB0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21BC50681CDCC40800E85CB0 /* AppDelegate.swift */; }; 13 | 21BC506B1CDCC40800E85CB0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21BC506A1CDCC40800E85CB0 /* ViewController.swift */; }; 14 | 21BC506E1CDCC40800E85CB0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 21BC506C1CDCC40800E85CB0 /* Main.storyboard */; }; 15 | 21BC50701CDCC40800E85CB0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 21BC506F1CDCC40800E85CB0 /* Assets.xcassets */; }; 16 | 21BC50731CDCC40800E85CB0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 21BC50711CDCC40800E85CB0 /* LaunchScreen.storyboard */; }; 17 | 21BC50971CDCC7B700E85CB0 /* ToggleMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21BC50961CDCC7B700E85CB0 /* ToggleMenu.swift */; }; 18 | 21BC50991CDCCBFD00E85CB0 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 21BC50981CDCCBFD00E85CB0 /* README.md */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 21448E651CDCFE0500677345 /* ToggleMenu.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = ToggleMenu.gif; sourceTree = ""; }; 23 | 217871E61CDDE28B00EC389F /* ToggleMenuStoryboard.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = ToggleMenuStoryboard.gif; sourceTree = ""; }; 24 | 21BC50651CDCC40800E85CB0 /* MenuToggle.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MenuToggle.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 21BC50681CDCC40800E85CB0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 26 | 21BC506A1CDCC40800E85CB0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 27 | 21BC506D1CDCC40800E85CB0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 28 | 21BC506F1CDCC40800E85CB0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29 | 21BC50721CDCC40800E85CB0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 30 | 21BC50741CDCC40800E85CB0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 21BC50961CDCC7B700E85CB0 /* ToggleMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToggleMenu.swift; sourceTree = ""; }; 32 | 21BC50981CDCCBFD00E85CB0 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 21BC50621CDCC40800E85CB0 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 21BC505C1CDCC40800E85CB0 = { 47 | isa = PBXGroup; 48 | children = ( 49 | 21448E651CDCFE0500677345 /* ToggleMenu.gif */, 50 | 217871E61CDDE28B00EC389F /* ToggleMenuStoryboard.gif */, 51 | 21BC50981CDCCBFD00E85CB0 /* README.md */, 52 | 21BC50671CDCC40800E85CB0 /* MenuToggle */, 53 | 21BC50661CDCC40800E85CB0 /* Products */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | 21BC50661CDCC40800E85CB0 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 21BC50651CDCC40800E85CB0 /* MenuToggle.app */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | 21BC50671CDCC40800E85CB0 /* MenuToggle */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 21BC50681CDCC40800E85CB0 /* AppDelegate.swift */, 69 | 21BC506A1CDCC40800E85CB0 /* ViewController.swift */, 70 | 21BC506C1CDCC40800E85CB0 /* Main.storyboard */, 71 | 21BC50961CDCC7B700E85CB0 /* ToggleMenu.swift */, 72 | 21BC506F1CDCC40800E85CB0 /* Assets.xcassets */, 73 | 21BC50711CDCC40800E85CB0 /* LaunchScreen.storyboard */, 74 | 21BC50741CDCC40800E85CB0 /* Info.plist */, 75 | ); 76 | path = MenuToggle; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 21BC50641CDCC40800E85CB0 /* MenuToggle */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 21BC508D1CDCC40900E85CB0 /* Build configuration list for PBXNativeTarget "MenuToggle" */; 85 | buildPhases = ( 86 | 21BC50611CDCC40800E85CB0 /* Sources */, 87 | 21BC50621CDCC40800E85CB0 /* Frameworks */, 88 | 21BC50631CDCC40800E85CB0 /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = MenuToggle; 95 | productName = MenuToggle; 96 | productReference = 21BC50651CDCC40800E85CB0 /* MenuToggle.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | 21BC505D1CDCC40800E85CB0 /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | LastSwiftUpdateCheck = 0730; 106 | LastUpgradeCheck = 0730; 107 | ORGANIZATIONNAME = Stav1; 108 | TargetAttributes = { 109 | 21BC50641CDCC40800E85CB0 = { 110 | CreatedOnToolsVersion = 7.3; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 21BC50601CDCC40800E85CB0 /* Build configuration list for PBXProject "MenuToggle" */; 115 | compatibilityVersion = "Xcode 3.2"; 116 | developmentRegion = English; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 21BC505C1CDCC40800E85CB0; 123 | productRefGroup = 21BC50661CDCC40800E85CB0 /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | 21BC50641CDCC40800E85CB0 /* MenuToggle */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | 21BC50631CDCC40800E85CB0 /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | 21BC50731CDCC40800E85CB0 /* LaunchScreen.storyboard in Resources */, 138 | 21BC50701CDCC40800E85CB0 /* Assets.xcassets in Resources */, 139 | 21448E661CDCFE0500677345 /* ToggleMenu.gif in Resources */, 140 | 217871E71CDDE28B00EC389F /* ToggleMenuStoryboard.gif in Resources */, 141 | 21BC506E1CDCC40800E85CB0 /* Main.storyboard in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | 21BC50611CDCC40800E85CB0 /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 21BC506B1CDCC40800E85CB0 /* ViewController.swift in Sources */, 153 | 21BC50691CDCC40800E85CB0 /* AppDelegate.swift in Sources */, 154 | 21BC50991CDCCBFD00E85CB0 /* README.md in Sources */, 155 | 21BC50971CDCC7B700E85CB0 /* ToggleMenu.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 21BC506C1CDCC40800E85CB0 /* Main.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 21BC506D1CDCC40800E85CB0 /* Base */, 166 | ); 167 | name = Main.storyboard; 168 | sourceTree = ""; 169 | }; 170 | 21BC50711CDCC40800E85CB0 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | 21BC50721CDCC40800E85CB0 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 21BC508B1CDCC40900E85CB0 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_ANALYZER_NONNULL = YES; 186 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 187 | CLANG_CXX_LIBRARY = "libc++"; 188 | CLANG_ENABLE_MODULES = YES; 189 | CLANG_ENABLE_OBJC_ARC = YES; 190 | CLANG_WARN_BOOL_CONVERSION = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 193 | CLANG_WARN_EMPTY_BODY = YES; 194 | CLANG_WARN_ENUM_CONVERSION = YES; 195 | CLANG_WARN_INT_CONVERSION = YES; 196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 197 | CLANG_WARN_UNREACHABLE_CODE = YES; 198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 199 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 200 | COPY_PHASE_STRIP = NO; 201 | DEBUG_INFORMATION_FORMAT = dwarf; 202 | ENABLE_STRICT_OBJC_MSGSEND = YES; 203 | ENABLE_TESTABILITY = YES; 204 | GCC_C_LANGUAGE_STANDARD = gnu99; 205 | GCC_DYNAMIC_NO_PIC = NO; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_OPTIMIZATION_LEVEL = 0; 208 | GCC_PREPROCESSOR_DEFINITIONS = ( 209 | "DEBUG=1", 210 | "$(inherited)", 211 | ); 212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 214 | GCC_WARN_UNDECLARED_SELECTOR = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 216 | GCC_WARN_UNUSED_FUNCTION = YES; 217 | GCC_WARN_UNUSED_VARIABLE = YES; 218 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 219 | MTL_ENABLE_DEBUG_INFO = YES; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = iphoneos; 222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 223 | }; 224 | name = Debug; 225 | }; 226 | 21BC508C1CDCC40900E85CB0 /* Release */ = { 227 | isa = XCBuildConfiguration; 228 | buildSettings = { 229 | ALWAYS_SEARCH_USER_PATHS = NO; 230 | CLANG_ANALYZER_NONNULL = YES; 231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 232 | CLANG_CXX_LIBRARY = "libc++"; 233 | CLANG_ENABLE_MODULES = YES; 234 | CLANG_ENABLE_OBJC_ARC = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_CONSTANT_CONVERSION = YES; 237 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 238 | CLANG_WARN_EMPTY_BODY = YES; 239 | CLANG_WARN_ENUM_CONVERSION = YES; 240 | CLANG_WARN_INT_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 245 | COPY_PHASE_STRIP = NO; 246 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 247 | ENABLE_NS_ASSERTIONS = NO; 248 | ENABLE_STRICT_OBJC_MSGSEND = YES; 249 | GCC_C_LANGUAGE_STANDARD = gnu99; 250 | GCC_NO_COMMON_BLOCKS = YES; 251 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 252 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 253 | GCC_WARN_UNDECLARED_SELECTOR = YES; 254 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 255 | GCC_WARN_UNUSED_FUNCTION = YES; 256 | GCC_WARN_UNUSED_VARIABLE = YES; 257 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 258 | MTL_ENABLE_DEBUG_INFO = NO; 259 | SDKROOT = iphoneos; 260 | VALIDATE_PRODUCT = YES; 261 | }; 262 | name = Release; 263 | }; 264 | 21BC508E1CDCC40900E85CB0 /* Debug */ = { 265 | isa = XCBuildConfiguration; 266 | buildSettings = { 267 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 268 | INFOPLIST_FILE = MenuToggle/Info.plist; 269 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 270 | PRODUCT_BUNDLE_IDENTIFIER = org.Stav1.MenuToggle; 271 | PRODUCT_NAME = "$(TARGET_NAME)"; 272 | }; 273 | name = Debug; 274 | }; 275 | 21BC508F1CDCC40900E85CB0 /* Release */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 279 | INFOPLIST_FILE = MenuToggle/Info.plist; 280 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 281 | PRODUCT_BUNDLE_IDENTIFIER = org.Stav1.MenuToggle; 282 | PRODUCT_NAME = "$(TARGET_NAME)"; 283 | }; 284 | name = Release; 285 | }; 286 | /* End XCBuildConfiguration section */ 287 | 288 | /* Begin XCConfigurationList section */ 289 | 21BC50601CDCC40800E85CB0 /* Build configuration list for PBXProject "MenuToggle" */ = { 290 | isa = XCConfigurationList; 291 | buildConfigurations = ( 292 | 21BC508B1CDCC40900E85CB0 /* Debug */, 293 | 21BC508C1CDCC40900E85CB0 /* Release */, 294 | ); 295 | defaultConfigurationIsVisible = 0; 296 | defaultConfigurationName = Release; 297 | }; 298 | 21BC508D1CDCC40900E85CB0 /* Build configuration list for PBXNativeTarget "MenuToggle" */ = { 299 | isa = XCConfigurationList; 300 | buildConfigurations = ( 301 | 21BC508E1CDCC40900E85CB0 /* Debug */, 302 | 21BC508F1CDCC40900E85CB0 /* Release */, 303 | ); 304 | defaultConfigurationIsVisible = 0; 305 | defaultConfigurationName = Release; 306 | }; 307 | /* End XCConfigurationList section */ 308 | }; 309 | rootObject = 21BC505D1CDCC40800E85CB0 /* Project object */; 310 | } 311 | --------------------------------------------------------------------------------