WWAssistiveTouch

Swift-5.6 iOS-14.0 Swift Package Manager-SUCCESS LICENSE

Introduction - 简介

WWAssistiveTouch

Installation with Swift Package Manager

dependencies: [
    .package(url: "https://github.com/William-Weng/WWAssistiveTouch.git", .upToNextMajor(from: "1.1.3"))
]

可用函数

函数 说明
init(touchViewController:frame:size:gap:icon:delegate:) 初始化AssistiveTouch
display(with:curve:) 显示AssistiveTouch的内容
dismiss(with:curve:) 隐藏AssistiveTouch的内容

WWAssistiveTouchDelegate

函数 说明
assistiveTouch(_:isTouched:) AssistiveTouch是否被按下
assistiveTouch(_:status:) AssistiveTouch的显示状态

Example

import UIKit
import WWAssistiveTouch

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    var assistiveTouch: WWAssistiveTouch!
    
    private lazy var touchViewController = { UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Touch") }()
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        assistiveTouch = WWAssistiveTouch(touchViewController: touchViewController, icon: UIImage(named: "Rec"), delegate: self)
        return true
    }
}

extension AppDelegate: WWAssistiveTouchDelegate {
    
    func assistiveTouch(_ assistiveTouch: WWAssistiveTouch, isTouched: Bool) {
        if (isTouched) { assistiveTouch.display() }
    }
    
    func assistiveTouch(_ assistiveTouch: WWAssistiveTouch, status: WWAssistiveTouch.Status) {
        print(status)
    }
}
import UIKit

final class TouchViewController: UIViewController {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        view.alpha = 0.5
        
        UIViewPropertyAnimator(duration: 0.25, curve: .linear) { [unowned self] in
            view.alpha = 1.0
        }.startAnimation()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        view.alpha = 0.0
    }
    
    @IBAction func dismissTouchView(_ sender: UIButton) {
        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
        appDelegate.assistiveTouch.dismiss()
    }
}