如何在iOS中添加双拇指滑块?以及为什么这个双滑块库不再适用于xcode 7

时间:2016-03-27 10:38:15

标签: ios xcode swift uislider

我有一个具有双滑块的应用程序,该项目在swift 1.2 / XCode 6中运行良好,我使用的插件是UIXRangeSlider

但问题是它在Swift 2 / XCode 7.2中使用时显示出奇怪的错误

enter image description here

我尝试修复错误,但是他们让我感到困惑,我尝试添加++++++++++ > + ; N i j < ; point to N [ > ; move pointer to i [ >> + > + <<< - ] ; add i to t1 and t2 > ; move to j [ < + > - ] ; add j i >> ; move to t2 [ << + >> - ] ; add t2 to j < ; move to t1 [ >> + << - ] ; add t1 to t3 >> ; move to t3 [ < + < + >> - ] ; move t3 to t1 and t2 <<<<< - ] >>> . 并删除它,没有机会,如何解决这些错误?或者你知道任何好的选择吗?

修改

修正了一些错误,我只需要帮助

enter image description here

1 个答案:

答案 0 :(得分:2)

您链接的代码存在以下几个问题:

  1. NSCoding&#39; init(coder: NSCoder)是一个可用的初始值设定项,因此这也需要一个可用的初始化程序:

    required init?(coder: NSCoder)
    {
        super.init(coder: coder)
        self.commonInit()
    }
    
  2. 方法setInactiveBarImagesetActiveBarImagesetRightThumbImagesetMiddleThumbImagesetLeftThumbImage与属性设置器冲突,因为它们具有相同名称的变量。 class(例如middleThumbImage)。编译器生成签名匹配setVariable:的方法,以便在Objective-C中使用。解决此问题的最佳方法是将方法体移动到每个变量的didSet处理程序中,例如:

    var activeBarImage:UIImage = UIImage() {
        didSet {
            self.activeBarView.removeFromSuperview()
            self.activeBarView = UIImageView(image: self.activeBarImage)
            self.activeBarView.userInteractionEnabled = false
            self.addSubview(self.activeBarView)
            self.orderSubviews()
            self.setNeedsLayout()
        }
    }
    
  3. 触摸跟踪方法写错了。超类接口接受UITouch?UIEvent? - 注意两个参数都是可选项。要修复错误,请更改参数并处理选项:

    override func beginTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?) -> Bool
    {
        guard let location = touch?.locationInView(self) else { return false }
    
        previousLocation = location
    
        // Hit test the thumb layers
        if leftThumbView.frame.contains(previousLocation)
        {
            trackedElement = .LeftThumb
        }
        else if rightThumbView.frame.contains(previousLocation)
        {
            trackedElement = .RightThumb
        }
        else if middleThumbView.frame.contains(previousLocation)
        {
            trackedElement = .MiddleThumb
        }
    
        return trackedElement != .None
    }
    
    override func continueTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?) -> Bool
    {
        guard let location = touch?.locationInView(self) else { return false }
    
        // 1. Determine by how much the user has dragged
        let deltaLocation = Double(location.x - previousLocation.x)
        let deltaValue = (Double(maximumValue) - Double(minimumValue)) * deltaLocation / Double(bounds.width /*- thumbWidth*/)
    
        switch trackedElement
        {
        case .LeftThumb:
            handleLeftThumbMove(location, delta: deltaValue)
        case .MiddleThumb:
            handleMiddleThumbMove(location, delta: deltaValue)
        case .RightThumb:
            handleRightThumbMove(location, delta: deltaValue)
        default:
            break
        }
    
        previousLocation = location
    
        return true
    }
    
    override func endTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?)
    {
        trackedElement = .None
    }
    
  4. 希望这可以解决问题!