RxJoystickView 0.0.2

RxJoystickView 0.0.2

Maintained by Tomas Friml.



  • By
  • 3ph

RxJoystickView

CI Status Version License Platform Swift

A simple reactive joystick view widget. Tracks horizontal and vertical position of dragged thumb from center in range [-1.0, 1.0]. Both axes can be individually disabled.

Screenshot

Usage

Simply add as custom view to storyboard or create programatically.

let joystickView = RxJoystickView()

Generic properties:

/// Flag determining if vertical line should be drawn.
/// Settings this to false also means vertical movement will be disabled.
joystickView.showVerticalLine = true

/// Flag determining if horizontal line should be drawn.
/// Settings this to false also means horizontal movement will be disabled.
joystickView.showHorizontalLine = true

/// Vertical line color
joystickView.verticalLineColor = UIColor.gray

/// Horizontal line color
joystickView.horizontalLineColor = UIColor.gray

/// Joystick thumb radius in pt
joystickView.thumbRadius = 10

/// Joystick thumb color
joystickView.thumbColor = UIColor.lightGray

Observing changes

// Horizontal thumb position changed: -1 is leftmost position, +1 is rightmost position.
joystickView
    .rx
    .horizontalPositionChanged
    .asDriver(onErrorJustReturn: 0)
    .drive(onNext: { position in
        NSLog("Horizontal position: \(position)")
    }).disposed(by: disposeBag)

// Vertical thumb position changed: -1 is topmost position, +1 is bottommost position.
joystickView
    .rx
    .verticalPositionChanged
    .asDriver(onErrorJustReturn: 0)
    .drive(onNext: { position in
        NSLog("Vertical position: \(position)")
    }).disposed(by: disposeBag)

Example

To run the example project, run pod try.

Requirements

iOS 8+, RxSwift.

Installation

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

pod 'RxJoystickView'

Author

Tomas Friml, [email protected]

License

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