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
248 changes: 144 additions & 104 deletions Classes/CAPSOptionsMenu.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Classes/CAPSOptionsMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CAPSOptionsMenuAction: NSObject {
/// - parameters:
/// - title: Title to be displayed on action button in menu
/// - handler: Completion handler for action button tap
init(title: String, handler: ((CAPSOptionsMenuAction) -> Void)) {
init(title: String, handler: @escaping ((CAPSOptionsMenuAction) -> Void)) {
actionHandler = handler
super.init()

Expand Down
28 changes: 14 additions & 14 deletions Classes/CAPSOptionsMenuButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import UIKit

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,31 @@ class CAPSOptionsMenuButton: UIButton {
}

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

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

override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
override 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
fileprivate func touchDown() {
UIView.animate(withDuration: 0.1, animations: { () -> 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()) {
fileprivate func touchUp() {
let delayTime = DispatchTime.now() + Double(Int64(0.15 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: delayTime) {
self.backgroundColor = self.optionsMenuButtonBackgroundColor
}
}
Expand Down
5 changes: 5 additions & 0 deletions OptionsMenuDemo/OptionsMenuDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
TargetAttributes = {
A677E12B1B9793ED009074A0 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0810;
};
};
};
Expand Down Expand Up @@ -312,23 +313,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = OptionsMenuDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.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;
};
A677E1401B9793ED009074A0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = OptionsMenuDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.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
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 {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> 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
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
12 changes: 6 additions & 6 deletions OptionsMenuDemo/OptionsMenuDemo/MenuTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MenuTableViewController: UITableViewController {
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 @@ -24,23 +24,23 @@ 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! MenuTableViewCell
cell.menuTitleLabel.text = "Small Menu"

return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let smallOptionsMenuVC: SmallOptionsMenuViewController = SmallOptionsMenuViewController(nibName: "SmallOptionsMenuViewController", bundle: nil)
self.navigationController?.pushViewController(smallOptionsMenuVC, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SmallOptionsMenuViewController: UIViewController {
}

func addOptionsMenu() {
optionsMenu = CAPSOptionsMenu(viewController: self, barButtonSystemItem: UIBarButtonSystemItem.Organize, keepBarButtonAtEdge: true)
optionsMenu = CAPSOptionsMenu(viewController: self, barButtonSystemItem: UIBarButtonSystemItem.organize, keepBarButtonAtEdge: true)
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)

Expand All @@ -49,20 +49,20 @@ class SmallOptionsMenuViewController: UIViewController {
optionsMenu?.addAction(menuAction3)
}

@IBAction func animationSegmentedControlChangedValue(sender: UISegmentedControl) {
@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) {
@IBAction func animationDurationSegmentedControlChangedValue(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
optionsMenu?.menuAnimationDuration(0.2)
} else {
Expand Down