小编A T*_*hka的帖子

如何访问UIColor的RGB值?

我有一个带有按钮的iOS绘图应用程序,让用户可以选择要绘制的颜色.由于我的画笔使用RGB值,但我的颜色常数是UIColors,我需要转换.我试过了

private var currentButton: UIButton? {
    willSet{
        currentButton?.layer.borderWidth = 0
    }
    didSet{
        currentButton?.layer.borderWidth = 2
        let index = (currentButton?.tag)! - 1
        drawView.brush.blue = colors[index].ciColor.blue //Here is where I get the error
        drawView.brush.green = colors[index].ciColor.green
        drawView.brush.red = colors[index].ciColor.red
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我在另一个StackOverflow问题中找到的.但是,当我尝试在第8行获取RGB值时,我收到此错误:

Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '*** -CIColor not defined for the UIColor UIExtendedSRGBColorSpace 1 1 1 1; need to first convert colorspace.'
Run Code Online (Sandbox Code Playgroud)

它清楚地说我需要转换色彩空间.但是CIColor.colorSpace只有获得.我究竟做错了什么?

core-image uicolor ios swift

4
推荐指数
1
解决办法
3370
查看次数

我可以将 UISearchController 与故事板一起使用吗?

有没有一种方法UISearchController可以让我使用故事板UISearchBar?我有一个带有导航栏的故事板 UI,其中包含我的搜索栏。如果我能保持这种方式就好了,因为以编程方式设置布局真的很不方便。我知道旧的UISearchDisplayController可以故事板。有没有办法用 UISearchController 做类似的事情?

uikit uisearchbar ios uistoryboard uisearchcontroller

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

如何禁用对UITableViewCell的删除操作?

我有一个UITableViewCell,在其中实现leadingSwipeActionsConfigurationForRowAt indexPath了允许用户在单元格上向右拖动以将其添加到收藏夹中的功能。但是,这样做时,也出现了向左拖动以删除的选项。我不希望这些单元格能够被删除。有没有一种方法可以执行滑动动作而不会出现删除动作?

uitableview uikit ios

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

Swift GCD:为什么信号处理程序在函数中不起作用

使用这个答案作为参考,我试图在我的 swift linux 脚本中实现一个信号处理程序,它将使程序保持活动状态直到 Ctrl-C,然后在收到 SIGINT 时运行一些清理。使用该答案中的代码在主函数中效果很好:

import Dispatch
import Foundation

signal(SIGINT, SIG_IGN) // // Make sure the signal does not terminate the application.

let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
sigintSrc.setEventHandler {
    print("Got SIGINT")
    // ...
    exit(0)
}
sigintSrc.resume()
dispatchMain()
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试将信号处理程序移动到一个函数中,如下所示:

public func registerSigint() {
    signal(SIGINT, SIG_IGN)
    let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
    sigintSrc.setEventHandler {
        print("Got SIGINT")
        exit(0)
    }
    sigintSrc.resume()
}
Run Code Online (Sandbox Code Playgroud)

...

registerSigint()
dispatchMain()
Run Code Online (Sandbox Code Playgroud)

程序在 CTRL-C SIGINT 上无限期挂起。为什么这表现不同?

sigint grand-central-dispatch swift

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