Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Swift 5 #440

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions SlideMenuControllerSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Pod::Spec.new do |s|
s.name = "SlideMenuControllerSwift"
s.version = "4.0.0"
s.version = "5.0.0"
s.summary = "iOS Slide View based on iQON, Feedly, Google+, Ameba iPhone app."
s.homepage = "https://github.com/dekatotoro/SlideMenuControllerSwift"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Yuji Hato" => "[email protected]" }
s.author = { "Yuji Hato" => "[email protected]" }
s.social_media_url = "https://twitter.com/dekatotoro"
s.platform = :ios
s.ios.deployment_target = "9.0"
Expand Down
376 changes: 179 additions & 197 deletions SlideMenuControllerSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,18 +26,14 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -53,8 +49,6 @@
ReferencedContainer = "container:SlideMenuControllerSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
24 changes: 0 additions & 24 deletions SlideMenuControllerSwiftTests/Info.plist

This file was deleted.

35 changes: 0 additions & 35 deletions SlideMenuControllerSwiftTests/SlideMenuControllerSwiftTests.swift

This file was deleted.

58 changes: 31 additions & 27 deletions Source/SlideMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import Foundation
import UIKit

// MARK: - SlideMenuControllerDelegate
@objc public protocol SlideMenuControllerDelegate {
@objc optional func leftWillOpen()
@objc optional func leftDidOpen()
Expand All @@ -18,6 +19,7 @@ import UIKit
@objc optional func rightDidClose()
}

// MARK: - SlideMenuOptions
public struct SlideMenuOptions {
public static var leftViewWidth: CGFloat = 270.0
public static var leftBezelWidth: CGFloat? = 16.0
Expand All @@ -29,7 +31,7 @@ public struct SlideMenuOptions {
public static var shadowOffset: CGSize = CGSize(width: 0,height: 0)
public static var panFromBezel: Bool = true
public static var animationDuration: CGFloat = 0.4
public static var animationOptions: UIViewAnimationOptions = []
public static var animationOptions: UIView.AnimationOptions = []
public static var rightViewWidth: CGFloat = 270.0
public static var rightBezelWidth: CGFloat? = 16.0
public static var rightPanFromBezel: Bool = true
Expand Down Expand Up @@ -128,7 +130,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
opacityframe.size.height = opacityframe.size.height - opacityOffset
opacityView = UIView(frame: opacityframe)
opacityView.backgroundColor = SlideMenuOptions.opacityViewBackgroundColor
opacityView.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleWidth]
opacityView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
opacityView.layer.opacity = 0.0
view.insertSubview(opacityView, at: 1)

Expand All @@ -141,7 +143,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
leftFrame.size.height = leftFrame.size.height - leftOffset
leftContainerView = UIView(frame: leftFrame)
leftContainerView.backgroundColor = UIColor.clear
leftContainerView.autoresizingMask = UIViewAutoresizing.flexibleHeight
leftContainerView.autoresizingMask = .flexibleHeight
view.insertSubview(leftContainerView, at: 2)
addLeftGestures()
}
Expand All @@ -155,7 +157,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
rightFrame.size.height = rightFrame.size.height - rightOffset
rightContainerView = UIView(frame: rightFrame)
rightContainerView.backgroundColor = UIColor.clear
rightContainerView.autoresizingMask = UIViewAutoresizing.flexibleHeight
rightContainerView.autoresizingMask = .flexibleHeight
view.insertSubview(rightContainerView, at: 3)
addRightGestures()
}
Expand Down Expand Up @@ -208,7 +210,6 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
}

open override func viewWillLayoutSubviews() {
// topLayoutGuideの値が確定するこのタイミングで各種ViewControllerをセットする
setUpViewController(mainContainerView, targetViewController: mainViewController)
setUpViewController(leftContainerView, targetViewController: leftViewController)
setUpViewController(rightContainerView, targetViewController: rightViewController)
Expand Down Expand Up @@ -356,7 +357,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
static var startPointOfPan: CGPoint = CGPoint.zero
static var wasOpenAtStartOfPan: Bool = false
static var wasHiddenAtStartOfPan: Bool = false
static var lastState : UIGestureRecognizerState = .ended
static var lastState : UIGestureRecognizer.State = .ended
}

@objc func handleLeftPanGesture(_ panGesture: UIPanGestureRecognizer) {
Expand All @@ -370,7 +371,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
}

switch panGesture.state {
case UIGestureRecognizerState.began:
case .began:
if LeftPanState.lastState != .ended && LeftPanState.lastState != .cancelled && LeftPanState.lastState != .failed {
return
}
Expand All @@ -389,7 +390,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
leftViewController?.beginAppearanceTransition(LeftPanState.wasHiddenAtStartOfPan, animated: true)
addShadowToView(leftContainerView)
setOpenWindowLevel()
case UIGestureRecognizerState.changed:
case .changed:
if LeftPanState.lastState != .began && LeftPanState.lastState != .changed {
return
}
Expand All @@ -398,7 +399,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
leftContainerView.frame = applyLeftTranslation(translation, toFrame: LeftPanState.frameAtStartOfPan)
applyLeftOpacity()
applyLeftContentViewScale()
case UIGestureRecognizerState.ended, UIGestureRecognizerState.cancelled:
case .ended, .cancelled:
if LeftPanState.lastState != .changed {
setCloseWindowLevel()
return
Expand Down Expand Up @@ -426,6 +427,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
}
case UIGestureRecognizerState.failed, UIGestureRecognizerState.possible:
break
@unknown default: break
}

LeftPanState.lastState = panGesture.state
Expand All @@ -436,7 +438,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
static var startPointOfPan: CGPoint = CGPoint.zero
static var wasOpenAtStartOfPan: Bool = false
static var wasHiddenAtStartOfPan: Bool = false
static var lastState : UIGestureRecognizerState = .ended
static var lastState : UIGestureRecognizer.State = .ended
}

@objc func handleRightPanGesture(_ panGesture: UIPanGestureRecognizer) {
Expand All @@ -450,7 +452,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
}

switch panGesture.state {
case UIGestureRecognizerState.began:
case .began:
if RightPanState.lastState != .ended && RightPanState.lastState != .cancelled && RightPanState.lastState != .failed {
return
}
Expand All @@ -470,7 +472,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {

addShadowToView(rightContainerView)
setOpenWindowLevel()
case UIGestureRecognizerState.changed:
case .changed:
if RightPanState.lastState != .began && RightPanState.lastState != .changed {
return
}
Expand All @@ -480,7 +482,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
applyRightOpacity()
applyRightContentViewScale()

case UIGestureRecognizerState.ended, UIGestureRecognizerState.cancelled:
case .ended, .cancelled:
if RightPanState.lastState != .changed {
setCloseWindowLevel()
return
Expand All @@ -505,7 +507,9 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {

track(.rightFlickClose)
}
case UIGestureRecognizerState.failed, UIGestureRecognizerState.possible:
case .failed, .possible:
break
@unknown default:
break
}

Expand All @@ -521,7 +525,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {

var duration: TimeInterval = Double(SlideMenuOptions.animationDuration)
if velocity != 0.0 {
duration = Double(fabs(xOrigin - finalXOrigin) / velocity)
duration = Double(abs(xOrigin - finalXOrigin) / velocity)
duration = Double(fmax(0.1, fmin(1.0, duration)))
}

Expand Down Expand Up @@ -555,7 +559,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {

var duration: TimeInterval = Double(SlideMenuOptions.animationDuration)
if velocity != 0.0 {
duration = Double(fabs(xOrigin - view.bounds.width) / velocity)
duration = Double(abs(xOrigin - view.bounds.width) / velocity)
duration = Double(fmax(0.1, fmin(1.0, duration)))
}

Expand Down Expand Up @@ -587,7 +591,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {

var duration: TimeInterval = Double(SlideMenuOptions.animationDuration)
if velocity != 0.0 {
duration = Double(fabs(xOrigin - finalXOrigin) / velocity)
duration = Double(abs(xOrigin - finalXOrigin) / velocity)
duration = Double(fmax(0.1, fmin(1.0, duration)))
}

Expand Down Expand Up @@ -618,7 +622,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {

var duration: TimeInterval = Double(SlideMenuOptions.animationDuration)
if velocity != 0.0 {
duration = Double(fabs(xOrigin - view.bounds.width) / velocity)
duration = Double(abs(xOrigin - view.bounds.width) / velocity)
duration = Double(fmax(0.1, fmin(1.0, duration)))
}

Expand Down Expand Up @@ -900,7 +904,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
if SlideMenuOptions.hideStatusBar {
DispatchQueue.main.async(execute: {
if let window = UIApplication.shared.keyWindow {
window.windowLevel = UIWindowLevelStatusBar + 1
window.windowLevel = UIWindow.Level.statusBar + 1
}
})
}
Expand All @@ -910,7 +914,7 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
if SlideMenuOptions.hideStatusBar {
DispatchQueue.main.async(execute: {
if let window = UIApplication.shared.keyWindow {
window.windowLevel = UIWindowLevelNormal
window.windowLevel = UIWindow.Level.normal
}
})
}
Expand All @@ -920,10 +924,10 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
if let viewController = targetViewController {
viewController.view.frame = targetView.bounds

if (!childViewControllers.contains(viewController)) {
addChildViewController(viewController)
if (!children.contains(viewController)) {
addChild(viewController)
targetView.addSubview(viewController.view)
viewController.didMove(toParentViewController: self)
viewController.didMove(toParent: self)
}
}
}
Expand All @@ -932,9 +936,9 @@ open class SlideMenuController: UIViewController, UIGestureRecognizerDelegate {
fileprivate func removeViewController(_ viewController: UIViewController?) {
if let _viewController = viewController {
_viewController.view.layer.removeAllAnimations()
_viewController.willMove(toParentViewController: nil)
_viewController.willMove(toParent: nil)
_viewController.view.removeFromSuperview()
_viewController.removeFromParentViewController()
_viewController.removeFromParent()
}
}

Expand Down Expand Up @@ -1042,12 +1046,12 @@ extension UIViewController {
}

public func addLeftBarButtonWithImage(_ buttonImage: UIImage) {
let leftButton: UIBarButtonItem = UIBarButtonItem(image: buttonImage, style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.toggleLeft))
let leftButton: UIBarButtonItem = UIBarButtonItem(image: buttonImage, style: UIBarButtonItem.Style.plain, target: self, action: #selector(self.toggleLeft))
navigationItem.leftBarButtonItem = leftButton
}

public func addRightBarButtonWithImage(_ buttonImage: UIImage) {
let rightButton: UIBarButtonItem = UIBarButtonItem(image: buttonImage, style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.toggleRight))
let rightButton: UIBarButtonItem = UIBarButtonItem(image: buttonImage, style: UIBarButtonItem.Style.plain, target: self, action: #selector(self.toggleRight))
navigationItem.rightBarButtonItem = rightButton
}

Expand Down