Skip to content

Commit

Permalink
Make alpha and animation duration settings configurable (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo authored and ykyouhei committed Jun 26, 2016
1 parent 10588fc commit 1a12371
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions KYDrawerController/Classes/KYDrawerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public class KYDrawerController: UIViewController, UIGestureRecognizerDelegate {
@objc public enum DrawerState: Int {
case Opened, Closed
}

private let _kContainerViewMaxAlpha : CGFloat = 0.2

private let _kDrawerAnimationDuration: NSTimeInterval = 0.25


/**************************************************************************/
// MARK: - Properties
/**************************************************************************/


@IBInspectable public var containerViewMaxAlpha: CGFloat = 0.2

@IBInspectable public var drawerAnimationDuration: NSTimeInterval = 0.25

@IBInspectable public var mainSegueIdentifier: String?

@IBInspectable public var drawerSegueIdentifier: String?
Expand Down Expand Up @@ -276,7 +276,7 @@ public class KYDrawerController: UIViewController, UIGestureRecognizerDelegate {

public func setDrawerState(state: DrawerState, animated: Bool) {
_containerView.hidden = false
let duration: NSTimeInterval = animated ? _kDrawerAnimationDuration : 0
let duration: NSTimeInterval = animated ? drawerAnimationDuration : 0

UIView.animateWithDuration(duration,
delay: 0,
Expand All @@ -297,7 +297,7 @@ public class KYDrawerController: UIViewController, UIGestureRecognizerDelegate {
self._drawerConstraint.constant = constant
self._containerView.backgroundColor = UIColor(
white: 0
, alpha: self._kContainerViewMaxAlpha
, alpha: self.containerViewMaxAlpha
)
}
self._containerView.layoutIfNeeded()
Expand Down Expand Up @@ -329,15 +329,15 @@ public class KYDrawerController: UIViewController, UIGestureRecognizerDelegate {
drawerState = _panDelta < 0 ? .Closed : .Opened
constant = min(_drawerConstraint.constant + delta, drawerWidth)
backGroundAlpha = min(
_kContainerViewMaxAlpha,
_kContainerViewMaxAlpha*(abs(constant)/drawerWidth)
containerViewMaxAlpha,
containerViewMaxAlpha*(abs(constant)/drawerWidth)
)
case .Right:
drawerState = _panDelta > 0 ? .Closed : .Opened
constant = max(_drawerConstraint.constant + delta, -drawerWidth)
backGroundAlpha = min(
_kContainerViewMaxAlpha,
_kContainerViewMaxAlpha*(abs(constant)/drawerWidth)
containerViewMaxAlpha,
containerViewMaxAlpha*(abs(constant)/drawerWidth)
)
}

Expand Down

0 comments on commit 1a12371

Please sign in to comment.