MultiDegreeLikeButton 0.1.0

MultiDegreeLikeButton 0.1.0

nukotsuka 维护。



  • 作者:
  • nukotsuka

MultiDegreeLikeButton

CI Status Version License Platform

MultiDegreeLikeButton 是一个“点赞按钮”,通过改变大小来表示点赞的程度。当用户轻按时,按钮会逐渐膨胀。如果按钮被3D触控,它会立即膨胀。

长按 3D 触控

要求

  • iOS 10.0+
  • Xcode 10.0+
  • Swift 4.0+

安装

MultiDegreeLikeButton 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中:

pod 'MultiDegreeLikeButton'

用法

基础

let heartButton = MultiDegreeLikeButton(imageStyle: .heart)
heartButton.completion = { _, degree in
    // do something
}

view.addSubview(heartButton)

自定义

let smileButton = MultiDegreeLikeButton(
    imageStyle: .custom(defaultImage: "smile_default", tappedImage: "smile_tapped"), 
    size: CGSize(width: 48, height: 48)
)
// custom properties
smileButton.likeDegree = 10
smileButton.durationLongPress = 5.0
smileButton.duration3DTouch = 0.5
smileButton.durationShrink = 0.5
smileButton.delayBeforeShrink = 0.1
smileButton.threshold3DTouch = 5.0
smileButton.completion = { button, degree in
    button.isEnabled = false
    // do something
}

view.addSubview(smileButton)

属性

  • isEnabled: Bool:如果此值为false,则不会调用completion,但动画仍然工作。
  • likeDegree: Int:喜爱程度,该值用于按钮的扩展比例。
  • durationLongPress: Double:触碰按钮时扩展动画的持续时间。
  • duration3DTouch: Double:3D触碰按钮时扩展动画的持续时间。
  • durationShrink: Double:触碰结束后收缩动画的持续时间。
  • delayBeforeShrink: Double:从触碰结束到开始收缩的延迟时间。
  • threshold3DTouch: CGFloat:开始3D触碰的阈值。
  • completionWithLikeDegree: ((MultiDegreeLikeButton, Int) -> Void)?:触碰完成后调用的回调函数。《Int》参数表示用户按下的时间计算出的喜爱程度,范围从1到《likeDegree》。

作者

nukotsuka, @nukotsuka

许可证

MultiDegreeLikeButton可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。