JoystickView 1.0.0

JoystickView 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2018
SPMSupports SPM

Maintained by CatchZeng.



  • By
  • CatchZeng

JoystickView

Version License Platform

support around,vertical,horizontal directions JoystickView

feature

Usage

1.init from code or xib. Do not forget set joystickBg and joystickThumb!

var joystickView = JoystickView()
joystickView.joystickBg = UIView()//replace with your custom background view
joystickView.joystickThumb = UIView()//replace with your custom thumb view

2.set delegate

joystickView.delegate = self

3.handle delegate

import JoystickView

class ViewController: UIViewController, JoystickViewDelegate{
    
    @IBOutlet weak var horizontalJoystick: JoystickView!
    @IBOutlet weak var verticalJoystick: JoystickView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        horizontalJoystick.form = .horizontal
        horizontalJoystick.delegate = self
        
        verticalJoystick.form = .vertical
        verticalJoystick.delegate = self
    }
    
    // MARK: JoystickViewDelegate
    
    func joystickView(_ joystickView: JoystickView, didMoveto x: Float, y: Float, direction: JoystickMoveDriection) {
        if joystickView == horizontalJoystick{
            print("horizontal joystick move to x:\(x) y:\(y) direction:\(direction.rawValue)")
        }else{
            print("vertical joystick move to x:\(x) y:\(y) direction:\(direction.rawValue)")
        }
    }
    
    func joystickViewDidEndMoving(_ joystickView: JoystickView) {
        if joystickView == horizontalJoystick{
            print("horizontal joystick did end moving")
        }else{
            print("vertical joystick did end moving")
        }
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS8+

Installation

JoystickView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "JoystickView"

Author

CatchZeng, http://catchzeng.com

License

JoystickView is available under the MIT license. See the LICENSE file for more info.