Skip to content

Commit

Permalink
*rename
Browse files Browse the repository at this point in the history
+add delegate
  • Loading branch information
vampire1514 committed Dec 19, 2019
1 parent eb69e85 commit a98812b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 14 additions & 0 deletions UIFlipView/Classes/UIFlipDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UIFlipDelegate.swift
// UIFlipView
//
// Created by Macbook Air on 2019/12/19.
//

import UIKit

public protocol UIFlipDelegate {
func didFinish()

func flipWillStart(duration: TimeInterval)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

open class FlipView: UIView {
open class UIFlipView: UIView {

/// 旋轉所需時間
public var spinTimeInterval = 1.0
Expand All @@ -17,6 +17,8 @@ open class FlipView: UIView {
/// 第二個View
public var behindView = UIView()

public var delegate: UIFlipDelegate?

private var isDisplayingPrimary = true

override init(frame: CGRect) {
Expand Down Expand Up @@ -58,14 +60,18 @@ open class FlipView: UIView {
}

@objc
final func flipView() {
public final func flipView() {

if (isDisplayingPrimary == true) {
behindView.isHidden = false
} else {
behindView.isHidden = true
}

if let delegate = self.delegate {
delegate.flipWillStart(duration: spinTimeInterval)
}

UIView.transition(from: isDisplayingPrimary ? frontView : behindView, to: isDisplayingPrimary ? behindView : frontView, duration: spinTimeInterval, options: [.transitionFlipFromLeft, .showHideTransitionViews]) { [weak self] (finish) in
guard let `self` = self else { return }
if finish {
Expand All @@ -75,6 +81,10 @@ open class FlipView: UIView {
} else {
self.behindView.isHidden = false
}

if let delegate = self.delegate {
delegate.didFinish()
}
}
}
}
Expand Down

0 comments on commit a98812b

Please sign in to comment.