HoldActions 0.1.3

HoldActions 0.1.3

Tienvv88维护。



  • 作者:
  • tienvv88

HoldActions

需求

iOS 17+

示例

要运行示例项目,请克隆仓库,并首先从Example目录运行pod install

安装

Cocoapods

HoldProcessAction可通过CocoaPods使用。要安装它,只需要将以下行添加到Podfile中

pod 'HoldActions', :git => 'https://github.com/tienvv88/HoldActions'

Swift 包管理器

  1. 文件 > Swift Packages > 添加包依赖
  2. 添加 https://github.com/tienvv88/HoldActions.git

或者

dependencies: [.package(url: "[https://github.com/ferhanakkan/AppCircleSampleProject.git](https://github.com/tienvv88/HoldActions.git)", .upToNextMajor(from: "0.1.0"))]

演示

hold_process_demo.mov

用法

SwiftUI

  import SwiftUI
  import HoldProcessAction

  struct SwiftUIViewDemo: View {
  
  @State private var status: String = "--"

  var body: some View {
      VStack {
          Text(status)
          HoldDownAction(title: "Test Hold Down Action",
                                              duration: 2.0,
                                              background: .black,
                                              loadingTint: .white.opacity(0.5),
                                              onChanged: {
              self.status = "Holding🚀"
          }, onCancel: {
              self.status = "Cancel🥲"
          }, onEnded: {
              self.status = "Done💖"
          })
      }
    }
  }

UIKit

 import UIKit
 import SwiftUI
 import HoldProcessAction

 class ViewController: UIViewController {

     private var statusLabel: UILabel!

     override func viewDidLoad() {
         super.viewDidLoad()
         // Do any additional setup after loading the view, typically from a nib.

         let holdDownAction = HoldDownAction(title: "Test Hold Down Action",
                                             duration: 2.0,
                                             background: .black,
                                             loadingTint: .white.opacity(0.5),
                                             onChanged: {
             self.statusLabel.text = "Holding🚀"
         }, onCancel: {
             self.statusLabel.text = "Cancel🥲"
         }, onEnded: {
             self.statusLabel.text = "Done💖"
         })

         let hostingView = UIHostingController(rootView: holdDownAction)

         let swiftUIView = hostingView.view ?? UIView()
         swiftUIView.translatesAutoresizingMaskIntoConstraints = false

         addChildViewController(hostingView)
         view.addSubview(swiftUIView)

         // Create and activate the constraints for the swiftui's view.
         NSLayoutConstraint.activate([
             swiftUIView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
             swiftUIView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
             swiftUIView.widthAnchor.constraint(equalToConstant: view.frame.width),
             swiftUIView.heightAnchor.constraint(equalToConstant: 100)
         ])

         hostingView.didMove(toParent: self)

         // setup status label
         statusLabel = UILabel()
         statusLabel.text = "--"
         statusLabel.textAlignment = .center
         statusLabel.translatesAutoresizingMaskIntoConstraints = false
         view.addSubview(statusLabel)

         NSLayoutConstraint.activate([
             statusLabel.centerXAnchor.constraint(equalTo: swiftUIView.centerXAnchor),
             statusLabel.bottomAnchor.constraint(equalTo: swiftUIView.topAnchor, constant: 10),
             statusLabel.widthAnchor.constraint(equalToConstant: 100),
             statusLabel.heightAnchor.constraint(equalToConstant: 20)
         ])
     }
 }

作者

tienvv88, [email protected]

许可协议

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