小编Tig*_*ran的帖子

如何使用 CIColorControls 通过 UISlider 和 Swift 更改亮度、对比度和饱和度

我正在开发一个照片滤镜应用程序,正如你所看到的,我添加了一个功能来调整对比度、亮度、饱和度和噪音。但问题是它们是独立工作的,这意味着当我开始编辑对比度时调整亮度时,它会返回到原始亮度。

界面

这是当我将亮度设置为最大(图像变白)然后尝试调整其对比度并且滑块更改原始图像的对比度时的预览。

过滤器独立工作!

在这里,我能够捕捉到释放滑块并将其值放在原始图像上的时刻,正如您所看到的,它起作用了,在演示中我将饱和度设置为 0,然后将相同饱和度的图片的对比度更改为 0。

作品!

问题是,现在当我单击滑块而不更改其值时,它会使当前值翻倍。例如,如果我将亮度设置为 5,将饱和度设置为 10,并决定在单击亮度时立即调整亮度,它的值会加倍,我不知道为什么。这是一个例子。我只是单击滑块而不更改其值。

在此输入图像描述

这是代码

  @objc func sliderValueDidChange(_ sender: UISlider!) {

    if sender.tag == 0 {

        let displayinPercentage: Int = Int((sender.value/200) * 10000)
        brightnessValueLabel.text = ("\(displayinPercentage)")
        selectedPictureImageView.image = originalImage
        let beginImage = CIImage(image: selectedPictureImageView.image!)
        self.filter = CIFilter(name: "CIColorControls")
        self.filter?.setValue(beginImage, forKey: kCIInputImageKey)
        self.filter.setValue(sender.value, forKey: kCIInputBrightnessKey)
        self.filteredImage = self.filter?.outputImage
        selectedPictureImageView.image = UIImage(cgImage: self.context.createCGImage(self.filteredImage!, from: (self.filteredImage?.extent)!)!)
        sliderValue = sender.value


    } else if sender.tag == 1 {

        let displayinPercentage: Int = Int((sender.value/200) * 10000)
        contrastValueLabel.text = ("\(displayinPercentage)")
        self.selectedPictureImageView.image = …
Run Code Online (Sandbox Code Playgroud)

core-graphics core-image ios cifilter swift

5
推荐指数
1
解决办法
9029
查看次数

如何在不制作 IBOutlet 的情况下以编程方式在 Swift 中为 UIView 高度约束设置动画?

我创建了一个按钮,它连接到顶部、前导和尾随并且具有固定的高度。当我点击按钮时,新的 UIView 实例应该带有动画。

import UIKit

class ViewController: UIViewController {

var topButton = UIButton()
var myView = UIView()

override func viewDidLoad() {
    super.viewDidLoad()

    topButton = UIButton(type: .roundedRect)
    topButton.setTitle("Add Acctivity", for: .normal)
    topButton.backgroundColor = UIColor.purple
    topButton.setTitleColor(UIColor.white, for: .normal)
    topButton.titleLabel?.font = UIFont(name: "System", size: 26)
    topButton.translatesAutoresizingMaskIntoConstraints = false
    topButton.addTarget(self, action: #selector(expandMenu), for: .touchUpInside)
    view.addSubview(topButton)

    topButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
    topButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
    topButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
    topButton.heightAnchor.constraint(equalToConstant: 70).isActive = true

    myView.backgroundColor = UIColor.blue
    myView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(myView) …
Run Code Online (Sandbox Code Playgroud)

animation uiview ios swift

2
推荐指数
1
解决办法
3794
查看次数

标签 统计

ios ×2

swift ×2

animation ×1

cifilter ×1

core-graphics ×1

core-image ×1

uiview ×1