我在列表中有两个按钮,在点击时,列表项的整个区域都会突出显示。有没有办法将两个按钮分开?
在这种情况下,我有一个“操作”按钮和一个“信息”按钮:
我发现了这个问题,但没有直接解决方案。
这是代码:
var body: some View {
HStack {
Text(control.name)
Spacer()
Button(action: {
print("action")
}) {
Text("Action")
}
.frame(width: 250 - 10)
.padding(5)
.background(Color(white: 0.9))
.cornerRadius(10)
.frame(width: 250)
Group {
Button(action: {
print("action")
}) {
Image(systemName: "info.circle")
.foregroundColor(.accentColor)
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AVDepthData从iOS 11中的相机获取深度数据,当我使用AVCapturePhotoCaptureDelegate设置photoOutput时,photo.depthData为nil.
所以我尝试用AVCaptureDepthDataOutput设置AVCaptureDepthDataOutputDelegate,我不知道如何捕获深度照片?
有没有人从AVDepthData获得图像?
编辑:
这是我试过的代码:
// delegates: AVCapturePhotoCaptureDelegate & AVCaptureDepthDataOutputDelegate
@IBOutlet var image_view: UIImageView!
@IBOutlet var capture_button: UIButton!
var captureSession: AVCaptureSession?
var sessionOutput: AVCapturePhotoOutput?
var depthOutput: AVCaptureDepthDataOutput?
var previewLayer: AVCaptureVideoPreviewLayer?
@IBAction func capture(_ sender: Any) {
self.sessionOutput?.capturePhoto(with: AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.jpeg]), delegate: self)
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
self.previewLayer?.removeFromSuperlayer()
self.image_view.image = UIImage(data: photo.fileDataRepresentation()!)
let depth_map = photo.depthData?.depthDataMap
print("depth_map:", depth_map) // is nil
}
func depthDataOutput(_ output: AVCaptureDepthDataOutput, didOutput depthData: AVDepthData, timestamp: CMTime, connection: AVCaptureConnection) …Run Code Online (Sandbox Code Playgroud) 我已经获得了 Xcode 13 的新测试版(测试版 4 + 5),现在我收到此构建错误:
主要参与者隔离类“My Class”与非隔离超类“My Super Class”具有不同的参与者隔离
不知道如何解决这个问题,我没有使用任何演员。
有谁知道这意味着什么?
我在这一行收到错误。
相关苹果论坛帖子。
编辑:
我发现应用程序中包中类的简单协议扩展可能会导致此问题:
protocol Test {
var test: String? { get }
}
extension ImagePIX: Test {
var test: String? { nil }
}
Run Code Online (Sandbox Code Playgroud)
在协议上添加前缀可以@MainActor解决该错误:
@MainActor protocol Test { ... }
Run Code Online (Sandbox Code Playgroud)
编辑:
已在Xcode 13 RC中修复
我正在写一个照片应用程序,我需要在带有双摄像头的iPhone相机视图中使用不同的覆盖(考虑到缩放ui),是否有正确的方法来检查双摄像头是否存在?
我试图拿到设备并检查非双摄像头iPhone是否为零,因此它仍会重新调整设备:
let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInDualCamera, mediaType: AVMediaTypeVideo, position: .back)
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何检测双摄像头?
我想在 Swift 中禁用 macOS 上 NSScrollView 内的 WKWebView 滚动。
我找到了一种使用 css 在 WKWebView 中禁用滚动的方法,虽然 WKWebView 仍然阻止 NSScrollView 滚动。
有谁知道如何做到这一点?
首先,我声明状态项:
var status_item: NSStatusItem?
Run Code Online (Sandbox Code Playgroud)
然后,我有一个关闭寡妇并添加状态项的功能:
self.view.window?.orderOut(self)
//self.view.window?.close()
self.status_item = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength)
if let status_button = self.status_item?.button {
status_button.image = NSImage(named: "StatusBarButtonImage")
status_button.action = #selector(statusBar(sender:))
}
Run Code Online (Sandbox Code Playgroud)
这是我的动作选择器方法,该方法应删除状态项并再次显示窗口。按下状态栏中的状态栏项时未调用它:
func statusBar(sender: AnyObject) {
print("status bar clicked")
self.status_item = nil
self.view.window?.orderFront(nil)
}
Run Code Online (Sandbox Code Playgroud)
有人知道我在做什么错吗?
我有一个Metal片段着色器,它返回一些带有alpha通道的透明颜色,我想在MTKView下显示一个UIView,但它们只有我得到的背景结果是黑色和"错误噪音".
MTLRenderPipelineDescriptor:
pipelineStateDescriptor.isAlphaToCoverageEnabled = true
pipelineStateDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
pipelineStateDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
Run Code Online (Sandbox Code Playgroud)
MTLRenderPassDescriptor:
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
Run Code Online (Sandbox Code Playgroud)
如果我改变了清晰的颜色,我可以在透明色下看到它,如果我跳过清晰的颜色,我会看到"错误噪音".明确的颜色alpha通道实际上做了什么吗?
有谁知道如何使MTKView透明?
更新:
这是使MTKView透明的神奇属性:
self.isOpaque = false
Run Code Online (Sandbox Code Playgroud) 我有一个 iPad 应用程序,可以轻松移植到 Mac。
我正在使用触摸开始/移动/结束,它移植得很好,但我想在 Mac 上的 iOS 应用程序上使用右键单击。
如何在 UIKit for Mac 应用程序中注册右键单击?
我的应用程序Binary Rejected第三次获得。崩溃日志没有帮助(我已经对它们进行了符号化,但它们不包含任何打印日志......)。
运行良好iPhone 6s,iPhone X并且iPad Pro 12.9
我正在iOS 12使用应用程序目标进行测试iOS 11
由于 Metal for iOS 无法在模拟器中运行,所以我没有测试过iOS 11
所以我得到了 Crashlytics 并获得了密钥的一些信息crash_info_entry_0:
...错误域=AGXMetalA8X代码=3“功能...正在使用与此操作系统不兼容的语言版本2.1。”...
它发生在iPad Air 2 (A8)跑步时iOS 11.4.1
所以我猜问题是iOS 11不支持金属language version 2.1
如何将语言版本更改为2.0?
更新1:
检查我的 Metal Lib 后,它确实有一个目标iOS 12。不过,它在应用程序目标为iOS 11. 我现在已将 Metal Lib 目标更改为iOS 11,我希望也更改 Metal 语言版本...
我希望编译器或应用商店上传器能够捕捉到这一点。
更新2:
有效!更改 Metal Lib 的 iOS 版本目标也会更改 Metal …
如何在SwiftUI中修边框?
我认为这会起作用:
.cornerRadius(10)
.border(Color.white)
Run Code Online (Sandbox Code Playgroud)
它不起作用。
这是我目前的解决方法:
.overlay(RoundedRectangle(cornerRadius: 10).stroke(lineWidth: 1).foregroundColor(.white))
Run Code Online (Sandbox Code Playgroud) swift ×5
ios ×3
metal ×3
macos ×2
swiftui ×2
alpha ×1
camera ×1
color-depth ×1
ios11 ×1
nsscrollview ×1
nsstatusbar ×1
nsstatusitem ×1
objective-c ×1
random ×1
scroll ×1
uikitformac ×1
window ×1
wkwebview ×1