RxJoystickView 0.0.2

RxJoystickView 0.0.2

Tomas Friml 维护。



  • By
  • 3ph

RxJoystickView

CI Status Version License Platform Swift

一个简单的响应式摇杆视图小部件。跟踪从中心到 [-1.0, 1.0] 范围内的水平方向和垂直方向的位置。两个轴都可以分别禁用。

Screenshot

使用方法

简单地将它添加为自定义视图到 storyboard,或者以编程方式创建。

let joystickView = RxJoystickView()

通用属性

/// 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

观察更改

// 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)

示例

要运行示例项目,请运行 pod try

需求

iOS 8+, RxSwift。

安装

RxJoystickView 可通过 CocoaPods 获取。要安装它,请将以下行添加到您的 Podfile 中

pod 'RxJoystickView'

作者

Tomas Friml,[email protected]

许可证

RxJoystickView 遵循 MIT 许可协议。更多信息请参阅 LICENSE 文件。