我一直在 SwiftUI 中寻找一种方法,仅以小时间隔获取今天的视图,就像 iOS 的日历应用程序一样,如果 SwiftUI 有默认的内置视图,那么那就太好了,如果没有,并且有一个 GitHub 库可以完成这项工作那么我也可以使用它,我在网上找到了一种在 SwiftUI 中显示年/月视图的方法:
import SwiftUI
fileprivate extension DateFormatter {
    static var month: DateFormatter {
        let formatter = DateFormatter()
        formatter.dateFormat = "MMMM"
        return formatter
    }
    static var monthAndYear: DateFormatter {
        let formatter = DateFormatter()
        formatter.dateFormat = "MMMM yyyy"
        return formatter
    }
}
fileprivate extension Calendar {
    func generateDates(
        inside interval: DateInterval,
        matching components: DateComponents
    ) -> [Date] {
        var dates: [Date] = []
        dates.append(interval.start)
        enumerateDates(
            startingAfter: interval.start,
            matching: components,
            matchingPolicy: .nextTime
        ) { …我正在编写一个 iOS14+ 应用程序,试图使用.onChange(of: scenePhase)它来代替进入前台或后台的应用程序。
但是当系统对话框弹出时(例如,要求配对设备时),我收到了该.inactive阶段 - 这与旧的 didEnterBackground/foreground 不同!
我目前不进行任何后台处理,因此我没有收到阶段.background- 只是.inactive然后.active再次。因此,\xe2\x80\x99s 没有简单的方法来区分系统对话框和实际进入后台之间的区别。
我想知道用户是否离开了我的应用程序并回来了。以后就不能用了吗?我不想使用旧的已弃用的方法。
\n我可以通过以下实现访问didFinishLaunchingWithOptions。但是,我需要UIWindow变量。我不知道如何得到它。我正在使用 Xcode 12 测试版。iOS14,SwiftUI 生命周期。
import SwiftUI
@main
struct SSOKit_DemoApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
class AppDelegate: NSObject, UIApplicationDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        print("hello world!!!")
        return true
    }
}
我最近将我的设备更新到了 iOS 14,现在每次打开应用程序时,我都会收到一条通知,其中包含“从另一个设备粘贴的 AppName...”我自己没有做任何事情来复制或粘贴用户剪贴板,所以经过一些测试后,我发现只有当我在 AppDelegate 中调用 FirebaseApp.configure() 时才会发生这种情况。
我仍然不确定哪个 Firebase pod 正在调用此粘贴方法,但有没有办法阻止它?
我正在为 iOS 14 制作一个 SwiftUI 应用程序,我有一个侧边栏列表,它使用 list 的新children:属性使列表可扩展:
 
但是,目前我只能在我精确单击披露箭头时展开此列表。例如,当我单击“我的酷项目”文本时,我也希望能够展开此列表。
这在“文件”应用程序中是可能的 - 当我单击“位置”文本时,我可以看到“位置”项的所有子项,但我不知道如何在我的应用程序中执行此操作。
 
为了澄清,List每个项目的项目是一个Text视图,子列表项目是NavigationLink
这种行为在 SwiftUI 中是否可能,甚至通过 onTapGesture 或除 a 以外的其他东西以编程方式进行List?提前感谢您的任何帮助/建议!
我想补充一个“撰写”按钮到.bottomBar的.toolbar我NavigationView。
添加一个Spacer()简单的几乎居中对齐项目:
struct HomeView: View {
    var body: some View {
        NavigationView {
            Text("Hello, World!")
                .navigationTitle("Hello, World!")
                .toolbar {
                    ToolbarItem(placement: .bottomBar) {
                        HStack {
                            Spacer()
                            Button(action: { print("Pressed") }) {
                                Image(systemName: "plus.circle.fill")
                                    .imageScale(.large)
                                    .font(.title)
                            }
                        }
                    }
                }
        }
    }
}
这会产生以下结果:
不是我所期望的。更奇怪的是,这并不是完全居中对齐,而是偏离了几个像素。
那么我该怎么做:
右对齐?
居中对齐?
谢谢
在带有 textField 的 iOS 14 TableView 中不起作用。有人有解决方案吗?
这是示例代码:
class TestController: UIViewController {
    let tableView: UITableView = {
        let tableView = UITableView(frame: .zero, style: .grouped)
        return tableView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .green
        view.addSubview(tableView)
        tableView.edgesToSuperview()
        tableView.backgroundColor = .gray
        tableView.register(TestCell.self, forCellReuseIdentifier: TestCell.reuseID)
        tableView.dataSource = self
    }
}
extension TestController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: TestCell.reuseID, …For some reason I'm unable to get an image background to aspectFill correctly in XCode Version 12.0, but only on the .systemMedium widget size. It seems to work perfectly on the small and large sizes.
I've got a pretty simple View:
import SwiftUI
@available(iOS 13.0.0, *)
struct Banana: View {
    var body: some View {
        VStack(alignment: .leading){
            Spacer()
            Text("Aardvark Exactlywhat")
                .font(.largeTitle)
                .bold()
                .padding(.bottom, 20)
                .padding(.leading, 20)
                .padding(.trailing, 20)
                .minimumScaleFactor(0.5)
                .foregroundColor(.white)
                .shadow(
                    color: Color.black,
                    radius: 1.0,
                    x: CGFloat(4),
                    y: CGFloat(4))
        } …当MCBrowserViewController调用
-[MCBrowserViewController advertiser:didNotStartAdvertisingPeer:]: unrecognized selector sent to instance
错误信息被抛出。
当MCAdvertiserAssistant尝试开始广告时
-[MCAdvertiserAssistant advertiser:didNotStartAdvertisingPeer:]: unrecognized selector sent to instance
错误信息被抛出。
被击中而无法继续。我的业务取决于MultipeerConnectivity框架。
任何帮助将不胜感激。
我正在为 iOS 14 构建一个小部件,并希望某些内容与左侧对齐,而其他一些内容在右侧。我该怎么做?
这是我现在的代码:
ZStack {
            HStack(alignment: .center, spacing: nil, content: {
                
                VStack(alignment: .leading, spacing: nil, content: {
                    Text("Heading")
                        .zIndex(2)
                        .shadow(radius: 5)
                    
                    Text("Subtitle")
                        .zIndex(1)
                        .shadow(radius: 2.5)
                })
                
            })
            Image("Image")
                .zIndex(-1)
        }
我希望标题和副标题文本与小部件的最左侧对齐,以便我可以在中间/右侧添加更多信息。
提前致谢!我对 SwiftUI 还很陌生,所以这一切都需要学习。