Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 94 additions & 81 deletions Classes/CAPSOptionsMenu.swift

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Classes/CAPSOptionsMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ public class CAPSOptionsMenuAction: NSObject {
/// - parameters:
/// - title: Title to be displayed on action button in menu
/// - handler: Completion handler for action button tap
public init(title: String, handler: ((CAPSOptionsMenuAction) -> Void)) {
actionHandler = handler
public init(title: String, handler: @escaping((CAPSOptionsMenuAction) -> Void)) {

actionHandler = handler;
super.init()

self.title = title
}


public convenience init(title: String, image: UIImage?, handler: ((CAPSOptionsMenuAction) -> Void) ) {
public convenience init(title: String, image: UIImage?, handler: @escaping ((CAPSOptionsMenuAction) -> Void) ) {
self.init(title: title, handler: handler)
self.image = image
}
Expand Down
23 changes: 11 additions & 12 deletions Classes/CAPSOptionsMenuButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import UIKit

public class CAPSOptionsMenuButton: UIButton {
var optionsMenuButtonBackgroundColor: UIColor = UIColor.whiteColor()
var optionsMenuButtonHighlightedColor: UIColor = UIColor.lightGrayColor()
var optionsMenuButtonBackgroundColor: UIColor = UIColor.white
var optionsMenuButtonHighlightedColor: UIColor = UIColor.lightGray

/// Options Action Initializer
///
Expand Down Expand Up @@ -42,31 +42,30 @@ public class CAPSOptionsMenuButton: UIButton {
}

// MARK: - Tap handling
override public func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
touchDown()
}

override public func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
touchUp()
}

override public func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
override public func touchesCancelled(_ touches: Set<UITouch>?, with event: UIEvent?) {
super.touchesCancelled(touches!, with: event)
touchUp()
}

// MARK: - Touch down/up
private func touchDown() {
UIView.animateWithDuration(0.1) { () -> Void in
UIView.animate(withDuration: 0.1) { () -> Void in
self.backgroundColor = self.optionsMenuButtonHighlightedColor
}
}

private func touchUp() {
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.15 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {

DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
self.backgroundColor = self.optionsMenuButtonBackgroundColor
}
}
Expand Down
14 changes: 11 additions & 3 deletions OptionsMenuDemo/OptionsMenuDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@
A677E1241B9793ED009074A0 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = CAPS;
TargetAttributes = {
A677E12B1B9793ED009074A0 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -238,8 +239,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -283,8 +286,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -303,6 +308,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -314,10 +320,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = OptionsMenuDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = caps.ua.edu.OptionsMenuDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -327,10 +334,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = OptionsMenuDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = caps.ua.edu.OptionsMenuDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 6 additions & 6 deletions OptionsMenuDemo/OptionsMenuDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// 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.
// 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.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// 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.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// 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.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
19 changes: 12 additions & 7 deletions OptionsMenuDemo/OptionsMenuDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8173.3" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="sdd-s2-Ygd">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="sdd-s2-Ygd">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8142"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Options Menu Demo-->
<scene sceneID="GJN-ZB-UqS">
<objects>
<tableViewController title="Options Menu Demo" id="vGh-jO-fLA" customClass="MenuTableViewController" customModule="OptionsMenuDemo" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="yuR-i9-tUe">
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<sections/>
<connections>
<outlet property="dataSource" destination="vGh-jO-fLA" id="k70-ec-fge"/>
Expand All @@ -31,10 +36,10 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="YAM-aE-DFz">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="barTintColor" red="0.18871212009999999" green="0.22811651229999999" blue="0.65021044019999996" alpha="1" colorSpace="calibratedRGB"/>
<color key="tintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="barTintColor" red="0.18871212009999999" green="0.22811651229999999" blue="0.65021044019999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</textAttributes>
</navigationBar>
<connections>
Expand Down
2 changes: 1 addition & 1 deletion OptionsMenuDemo/OptionsMenuDemo/MenuTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MenuTableViewCell: UITableViewCell {
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
Expand Down
25 changes: 15 additions & 10 deletions OptionsMenuDemo/OptionsMenuDemo/MenuTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
//

import UIKit
import Foundation


class MenuTableViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Options Menu Demo"
self.tableView.registerNib(UINib(nibName: "MenuTableViewCell", bundle: nil), forCellReuseIdentifier: "MenuTableViewCell")
self.tableView.register(UINib(nibName: "MenuTableViewCell", bundle: nil), forCellReuseIdentifier: "MenuTableViewCell")
}

override func didReceiveMemoryWarning() {
Expand All @@ -23,26 +25,29 @@ class MenuTableViewController: UITableViewController {
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: MenuTableViewCell = tableView.dequeueReusableCellWithIdentifier("MenuTableViewCell", forIndexPath: indexPath) as! MenuTableViewCell

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell: MenuTableViewCell = tableView.dequeueReusableCell(withIdentifier: "MenuTableViewCell", for: indexPath as IndexPath) as! MenuTableViewCell
cell.menuTitleLabel.text = "Small Menu"

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let smallOptionsMenuVC: SmallOptionsMenuViewController = SmallOptionsMenuViewController(nibName: "SmallOptionsMenuViewController", bundle: nil)
self.navigationController?.pushViewController(smallOptionsMenuVC, animated: true)
}



}
12 changes: 8 additions & 4 deletions OptionsMenuDemo/OptionsMenuDemo/MenuTableViewController.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MenuTableViewController" customModule="OptionsMenuDemo" customModuleProvider="target">
Expand All @@ -12,9 +16,9 @@
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="dataSource" destination="-1" id="Tng-2m-Rnh"/>
<outlet property="delegate" destination="-1" id="9aC-8N-iBw"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,55 @@ class SmallOptionsMenuViewController: UIViewController {

func addOptionsMenu() {

let addButton = UIBarButtonItem(barButtonSystemItem: .Organize, target: nil, action: "null")
let addButton = UIBarButtonItem(barButtonSystemItem: .organize, target: self, action: nil)
self.navigationItem.rightBarButtonItem = addButton


optionsMenu = CAPSOptionsMenu(viewController: self, barButtonItem: addButton, keepBarButtonAtEdge: true)

// optionsMenu = CAPSOptionsMenu(viewController: self, barButtonSystemItem: .Organize, keepBarButtonAtEdge: true)
//optionsMenu = CAPSOptionsMenu(viewController: self, barButtonSystemItem: .Organize, keepBarButtonAtEdge: true)

optionsMenu?.menuActionButtonsHighlightedColor(color: UIColor(red: 242.0/255.0, green: 242.0/255.0, blue: 242.0/255.0, alpha: 1.0))
optionsMenu?.menuCornerRadius = 2.0

optionsMenu?.menuActionButtonsHighlightedColor(UIColor(red: 242.0/255.0, green: 242.0/255.0, blue: 242.0/255.0, alpha: 1.0))
optionsMenu?.menuCornerRadius(2.0)

let menuAction1: CAPSOptionsMenuAction = CAPSOptionsMenuAction(title: "Action Title 1") { (action: CAPSOptionsMenuAction) -> Void in
print("Tapped Action Button 1")
}

menuAction1.image = UIImage(named: "ic_audio_24x24")

optionsMenu?.addAction(menuAction1)
optionsMenu?.addAction(action: menuAction1)

let menuAction2: CAPSOptionsMenuAction = CAPSOptionsMenuAction(title: "Action Title 2") { (action: CAPSOptionsMenuAction) -> Void in
print("Tapped Action Button 2")
}
optionsMenu?.addAction(menuAction2)
optionsMenu?.addAction(action: menuAction2)

let menuAction3: CAPSOptionsMenuAction = CAPSOptionsMenuAction(title: "Action Title 3") { (action: CAPSOptionsMenuAction) -> Void in
print("Tapped Action Button 3")
}
optionsMenu?.addAction(menuAction3)
optionsMenu?.addAction(action: menuAction3)
}

@IBAction func animationSegmentedControlChangedValue(sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
durationSegmentedControl.hidden = false
optionsMenu?.menuAnimationOption(AnimationOption.Expand)
durationSegmentedControl.isHidden = false
optionsMenu?.menuAnimationOption = AnimationOption.expand
} else if sender.selectedSegmentIndex == 1 {
durationSegmentedControl.hidden = false
optionsMenu?.menuAnimationOption(AnimationOption.Fade)
durationSegmentedControl.isHidden = false
optionsMenu?.menuAnimationOption = AnimationOption.fade
} else {
durationSegmentedControl.hidden = true
optionsMenu?.menuAnimationOption(AnimationOption.None)
durationSegmentedControl.isHidden = true
optionsMenu?.menuAnimationOption = AnimationOption.none
}
}

@IBAction func animationDurationSegmentedControlChangedValue(sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
optionsMenu?.menuAnimationDuration(0.2)
optionsMenu?.menuAnimationDuration = 0.2
} else {
optionsMenu?.menuAnimationDuration(0.0)
optionsMenu?.menuAnimationDuration = 0.0
}
}
}
Loading