滑块放慢和不平滑移动(sliders slow down and don't move sm

2019-10-29 06:41发布

我在做一个应用程序“照片编辑器”。 我是初学者迅速。 我有我的滑块的一个问题。 因为我需要他们不工作。 可能有人知道,我怎么能解决这个问题呢?

滑块无法正常工作,我需要用它帮助。 我不知道,为什么它的工作这样。

import UIKit

class ViewControllerFilters: UIViewController {

@IBOutlet weak var imageView: UIImageView!
var image: UIImage? = nil
var filter = CIFilter(name: "CISepiaTone")
var filteredImage: CIImage? = nil


@IBOutlet weak var slider: UISlider!
let context = CIContext()

@IBOutlet weak var slider2: UISlider!
@IBOutlet weak var slider3: UISlider!

@IBOutlet weak var slider4: UISlider!

override func viewDidLoad() {
    super.viewDidLoad()


    self.imageView.image = image
    self.slider.addTarget(self, action: #selector(sliderValueDidChange(sender:)), for: .valueChanged )
    self.slider2.addTarget(self, action: #selector(sliderValueDidChange(sender:)), for: .valueChanged)
    self.slider3.addTarget(self, action: #selector(sliderValueDidChange(sender:)), for: .valueChanged)
    self.slider4.addTarget(self, action: #selector(sliderValueDidChange(sender:)), for: .valueChanged)


}


let colorControlsFilter = CIFilter(name: "CIColorControls")!
let sepiaFilter = CIFilter(name:"CISepiaTone")!
let sharp = CIFilter(name: "CISharpenLuminance")!




@objc func sliderValueDidChange(sender: UISlider!) {
    switch sender.tag {
    case 0:
        let value = sender.value
        self.sharp.setValue(value, forKey: kCIInputSharpnessKey)
    case 1:
        let value = sender.value
        self.colorControlsFilter.setValue(value, forKey: kCIInputBrightnessKey)
    case 2:
        let value = sender.value
        self.colorControlsFilter.setValue(value, forKey: kCIInputContrastKey)
    case 3:
        let value = sender.value
        self.colorControlsFilter.setValue(value, forKey: kCIInputSaturationKey)
    default:
        print("no such elements")
    }

    self.updateImage()
}

func updateImage() {
    let originalCIImage = CIImage(image: self.image!)
    self.colorControlsFilter.setValue(originalCIImage, forKey: kCIInputImageKey)

    self.sharp.setValue(self.colorControlsFilter.outputImage, forKey: kCIInputImageKey)
    self.imageView.image = UIImage(ciImage: self.sharp.outputImage!)

}

我需要一个平滑移动我的滑块,因为这是不可能与它合作。

文章来源: sliders slow down and don't move smoothly