我已经有了一个ActionSheet,可以在iPhone设备上正常显示。但它在iPad上崩溃。说它需要弹出窗口的位置。有人用过此代码吗?我正在使用iOS 13 beta 3和Xcode 11 beta3。(这使用的是一个表示ActionSheet的版本,该版本在beta 2中不可用)
import SwiftUI
struct ContentView : View {
@State var showSheet = false
var body: some View {
VStack {
Button(action: {
self.showSheet.toggle()
}) {
Text("Show")
}
.presentation($showSheet) { () -> ActionSheet in
ActionSheet(title: Text("Hello"))
}
}
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Run Code Online (Sandbox Code Playgroud) 因此,当我在SwiftUI中列出列表时,会获得“免费”的主从详细信息拆分视图。
因此,例如:
import SwiftUI
struct ContentView : View {
var people = ["Angela", "Juan", "Yeji"]
var body: some View {
NavigationView {
List {
ForEach(people, id: \.self) { person in
NavigationLink(destination: Text("Hello!")) {
Text(person)
}
}
}
Text("")
}
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
如果iPad模拟器在横向,并且第一个详细信息屏幕是表情符号,我会得到splitView。但是,如果人们点击名称,则详细信息视图为“ Hello!”。
一切都很棒。
但是,如果我以纵向方式运行iPad,则表情符号会向用户表示欢迎,然后就不会显示列表。您必须从左向右滑动才能使列表从侧面显示。
有谁知道一种显示导航栏的方法,该导航栏可以让用户点击以查看左侧的项目列表?因此,它不是仅带有表情符号的屏幕吗?
我不愿意留下一个注释,上面写着“从左侧扫入以查看文件/人员/所有内容的列表”
我记得UISplitViewController有一个可以设置的折叠属性。这里有这样的东西吗?
我想知道是否有通过 SwiftUI 导出或共享文件的好方法。似乎没有一种方法可以包装 UIActivityViewController 并直接呈现它。我已经使用 UIViewControllerRepresentable 来包装 UIActivityViewController,如果我将它呈现在 SwiftUI Modal 中,它就会崩溃。
我能够创建一个通用的 UIViewController,然后从那里调用一个呈现 UIActivityViewController 的方法,但这是很多包装。
如果我们想使用 SwiftUI 从 Mac 共享,有没有办法包装 NSSharingServicePicker?
无论如何,如果有人有他们如何做到这一点的例子,我们将不胜感激。
如果用户使用 Xcode 中的 Document App 模板创建 SwiftUI 应用程序,macOS 会使用新文档启动他们。这很好。我可以使用它在新文档中显示入职 UI。
但是,在 iOS 上运行相同的应用程序时,用户会收到股票文档视图控制器的欢迎,以创建或选择文档。
这没有帮助,因为我没有办法展示入职信息或任何其他自定义信息。
我确实注意到,如果您将 WindowGroup 添加到场景中,应用程序将显示该窗口组。但是我不知道如何让用户进入选择器 UI。
有没有人想出如何在这个基于 DocumentGroup 的应用程序上做一些事情?
这是一个完整的文档应用程序
import SwiftUI
import UniformTypeIdentifiers
@main
struct DocumentTestApp: App {
var body: some Scene {
DocumentGroup(newDocument: DocumentTestDocument()) { file in
ContentView(document: file.$document)
}
}
}
struct ContentView: View {
@Binding var document: DocumentTestDocument
var body: some View {
TextEditor(text: $document.text)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(document: .constant(DocumentTestDocument()))
}
}
extension UTType { …Run Code Online (Sandbox Code Playgroud) 我正在尝试将音频缓冲区转换为不同的格式,并且我正在使用 AVAudioConverter。当您具有相同的采样率并且不需要使用 AVAudioConverterInputBlock 时,AVAudioConverter 会完成这项工作。
但是如果我处理相同的采样率,我的音频数据会出现奇怪的口吃。我有一种感觉,我没有很好地处理输入块。输出有重复两到三遍的单词。下面是完整的方法:
func sendAudio(audioFile: URL, completionHandler: @escaping (Bool, Bool, Data?)->Void) {
createSession(){ sessionUrl, observeURL, session in
let file = try! AVAudioFile(forReading: audioFile)
let formatOfAudio = file.processingFormat
self.engine = AVAudioEngine()
guard let input = self.engine.inputNode else {
print("no input")
return
}
//The audio in format in this case is: <AVAudioFormat 0x61800009d010: 2 ch, 44100 Hz, Float32, non-inter>
let formatIn = formatOfAudio
let formatOut = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true)
let mixer = AVAudioMixerNode()
self.engine.attach(mixer) …Run Code Online (Sandbox Code Playgroud) 我正在努力将此代码转换为Swift,这有助于我获取可视化的音频数据.我在Obj C中使用的代码,运行良好,是:
while (reader.status == AVAssetReaderStatusReading) {
AVAssetReaderTrackOutput *trackOutput = (AVAssetReaderTrackOutput *)[reader.outputs objectAtIndex:0];
self.sampleBufferRef = [trackOutput copyNextSampleBuffer];
if (self.sampleBufferRef) {
CMBlockBufferRef blockBufferRef = CMSampleBufferGetDataBuffer(self.sampleBufferRef);
size_t bufferLength = CMBlockBufferGetDataLength(blockBufferRef);
void *data = malloc(bufferLength);
CMBlockBufferCopyDataBytes(blockBufferRef, 0, bufferLength, data);
SInt16 *samples = (SInt16 *)data;
int sampleCount = bufferLength / bytesPerInputSample;
for (int i=0; i<sampleCount; i+=100) {
Float32 sample = (Float32) *samples++;
sample = decibel(sample);
sample = minMaxX(sample,noiseFloor,0);
tally += sample;
for (int j=1; j<channelCount; j++)
samples++;
tallyCount++;
if (tallyCount == downsampleFactor) {
sample …Run Code Online (Sandbox Code Playgroud) 客户希望通过API调用下载它们来动态地将字体添加到iOS应用程序.
这可能吗?我挖掘的所有资源都显示了如何手动将.ttf文件拖到Xcode并将其添加到plist中.是否可以下载字体并以编程方式在即时客户端使用它?
谢谢.
我正在尝试使用 Accelerate 框架将一些 python numpy 代码移植到 Swift。
在python中我写
import numpy as np
frames = np.array([1.0, 2.0, 3.0, 4.0])
fftArray = np.fft.fft(frames, len(frames))
print(fftArray)
Run Code Online (Sandbox Code Playgroud)
输出是:
[10.+0.j -2.+2.j -2.+0.j -2.-2.j]
Run Code Online (Sandbox Code Playgroud)
所以在 Swift 中,我试图像这样计算 FFT:
import Foundation
import Accelerate
func fftAnalyzer(frameOfSamples: [Float]) {
// As above, frameOfSamples = [1.0, 2.0, 3.0, 4.0]
let analysisBuffer = frameOfSamples
let frameCount = frameOfSamples.count
var reals = [Float]()
var imags = [Float]()
for (idx, element) in analysisBuffer.enumerated() {
if idx % 2 == 0 {
reals.append(element)
} …Run Code Online (Sandbox Code Playgroud)