Skip to content

Commit

Permalink
fix some naming issues, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
superk589 committed Apr 6, 2017
1 parent 73dbf14 commit da77fdc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ drawerController.mainCoverView.backgroundColor = UIColor.black.withAlphaComponen

### set left and right side width
```swift
drawerController.defalutRightWidth = 300
drawerController.defalutLeftWidth = 300
drawerController.defaultRightWidth = 300
drawerController.defaultLeftWidth = 300

```
### set shadow width
Expand Down Expand Up @@ -102,7 +102,7 @@ drawerController.rightVC = nil
drawerController.leftVC = nil
```

### use ZKDrawerController as your root controller and show controller-based side controller.
### use ZKDrawerController as your root controller and show various main controller-based side controllers.
```swift
// in AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Expand All @@ -122,8 +122,8 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions lau

// in ViewController.swift
var drawerController: ZKDrawerController!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let rightVC = UIViewController()
drawerController.rightVC = rightVC
}
Expand Down
2 changes: 1 addition & 1 deletion ZKDrawerController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ZKDrawerController"
s.version = "0.1.0"
s.version = "0.1.1"
s.summary = "An iOS drawer controller in swift."
s.description = <<-DESC
A light-weighted iOS drawer controller in swift.
Expand Down
71 changes: 45 additions & 26 deletions ZKDrawerController/Core/ZKDrawerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
/// 主视图蒙层
open var mainCoverView: ZKDrawerCoverView!

var lastStatus: ZKDrawerStatus = .center

/// 阴影视图的宽度
open var shadowWidth: CGFloat = 5 {
didSet {
Expand All @@ -81,34 +79,35 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
}
}


/// 主视图控制器
open var mainVC: UIViewController! {
didSet {
removeOldVC(vc: oldValue)
setupMainVC(vc: mainVC)
remove(vc: oldValue)
setupMain(vc: mainVC)
}
}

/// 右侧抽屉视图控制器
open var rightVC: UIViewController? {
didSet {
removeOldVC(vc: oldValue)
setupRightVC(vc: rightVC)
remove(vc: oldValue)
setupRight(vc: rightVC)
}
}

/// 左侧抽屉视图控制器
open var leftVC: UIViewController? {
didSet {
removeOldVC(vc: oldValue)
setupLeftVC(vc: leftVC)
remove(vc: oldValue)
setupLeft(vc: leftVC)
}
}

/// 主视图在抽屉出现后的缩放比例
open var mainScale: CGFloat = 1

var lastStatus: ZKDrawerStatus = .center

open weak var delegate: ZKDrawerControllerDelegate?

public convenience init(main: UIViewController, right: UIViewController) {
Expand Down Expand Up @@ -143,9 +142,9 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
self.rightVC = right
self.leftVC = left

setupMainVC(vc: main)
setupLeftVC(vc: left)
setupRightVC(vc: right)
setupMain(vc: main)
setupLeft(vc: left)
setupRight(vc: right)

mainCoverView = ZKDrawerCoverView()
main.view.addSubview(mainCoverView)
Expand Down Expand Up @@ -190,7 +189,12 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
}
}

@available(iOS, deprecated: 1.0, message: "use setupLeft(vc: UIViewController) instead")
func setupLeftVC(vc: UIViewController?) {
setupLeft(vc: vc)
}

func setupLeft(vc: UIViewController?) {
if let controller = vc {
self.addChildViewController(controller)
}
Expand All @@ -212,7 +216,12 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
}
}

@available(iOS, deprecated: 1.0, message: "use setupRight(vc: UIViewController) instead")
func setupRightVC(vc: UIViewController?) {
setupRight(vc: vc)
}

func setupRight(vc: UIViewController?) {
if let controller = vc {
self.addChildViewController(controller)
}
Expand All @@ -229,13 +238,13 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
containerView.bringSubview(toFront: leftShadow)
containerView.bringSubview(toFront: rightShadow)
}

} else {
rightWidth = 0
}
}

func setupMainVC(vc: UIViewController) {
func setupMain(vc: UIViewController) {
self.addChildViewController(vc)
containerView.addSubview(vc.view)
vc.view.snp.makeConstraints { (make) in
Expand All @@ -247,7 +256,8 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
}
}

func removeOldVC(vc: UIViewController?) {

func remove(vc: UIViewController?) {
vc?.view.snp.removeConstraints()
vc?.view.removeFromSuperview()
vc?.removeFromParentViewController()
Expand All @@ -259,28 +269,31 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {

/// 弹出预先设定好的抽屉ViewController
///
/// - Parameter animated: 是否有过度动画
/// - Parameter animated: 是否有过渡动画
open func show(animated: Bool) {
if let frame = rightVC?.view.frame ?? leftVC?.view.frame {
self.containerView.scrollRectToVisible(frame, animated: animated)
}
}

@available(iOS, deprecated: 1.0, message: "use showLeft(vc: UIViewController, animated: Bool) instead")
open func showRightVC(_ vc: UIViewController, animated: Bool) {
showRight(vc: vc, animated: animated)
}

/// 传入一个新的ViewController并从右侧弹出
///
/// - Parameters:
/// - vc: ViewController
/// - animated: 是否有过度动画
open func showRightVC(_ vc: UIViewController, animated: Bool) {
/// - animated: 是否有过渡动画
open func showRight(vc: UIViewController, animated: Bool) {
rightVC = vc
show(animated: animated)
}


/// 隐藏右侧抽屉
/// 隐藏抽屉
///
/// - Parameter animated: 是否有过度动画
/// - Parameter animated: 是否有过渡动画
open func hide(animated: Bool) {
if #available(iOS 9.0, *) {
self.containerView.setContentOffset(CGPoint.init(x: self.leftWidth, y: 0), animated: animated)
Expand All @@ -293,16 +306,20 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
}


@available(iOS, deprecated: 1.0, message: "use showLeft(vc: UIViewController, animated: Bool) instead")
open func showleftVC(_ vc: UIViewController, animated: Bool) {
showLeft(vc: vc, animated: animated)
}

/// 传入一个新的ViewController并从左侧弹出
///
/// - Parameters:
/// - vc: ViewController
/// - animated: 是否有过度动画
open func showleftVC(_ vc: UIViewController, animated: Bool) {
/// - animated: 是否有过渡动画
open func showLeft(vc: UIViewController, animated: Bool) {
leftVC = vc
show(animated: animated)
}

}

extension ZKDrawerController: UIScrollViewDelegate {
Expand Down Expand Up @@ -348,7 +365,7 @@ extension ZKDrawerController: UIScrollViewDelegate {
let width = scrollView.frame.size.width
let offsetX = scrollView.contentOffset.x

/// 0 to 1 progress of the drawer showing
/// 0 to 1
let progress: CGFloat = {
if status == .left {
return (leftWidth - offsetX) / leftWidth
Expand Down Expand Up @@ -443,7 +460,7 @@ extension ZKDrawerController: UIScrollViewDelegate {

extension ZKDrawerController {

var rightWidth:CGFloat {
var rightWidth: CGFloat {
set {
containerView.rightWidth = newValue
mainVC.view.snp.updateConstraints { (update) in
Expand Down Expand Up @@ -519,6 +536,8 @@ extension ZKDrawerController {
}
}


/// 当前状态
open var status: ZKDrawerStatus {
if containerView.contentOffset.x < leftWidth {
return .left
Expand Down

0 comments on commit da77fdc

Please sign in to comment.