GDPerformanceView-Swift 2.1.1

GDPerformanceView-Swift 2.1.1

测试已测试
Lang语言 SwiftSwift
许可证 MIT
释放最后发布2020 年 9 月
SPM支持 SPM

Gavrilov Daniil 维护。



  • Gavrilov Daniil

GDPerformanceView-Swift

显示帧率,CPU和内存使用情况,设备型号,应用和 iOS 版本在状态栏上,并通过代理报告帧率,CPU和内存使用情况。

Carthage compatible Pod Version Swift Version Swift Version Swift Version Plaform License MIT

Alt text Alt text Alt text Alt text

安装

只需将 GDPerformanceMonitoring 文件夹及其文件添加到您的项目中,或使用 CocoaPods。

Carthage

创建一个包含框架的 Cartfile 并运行 carthage update。按照说明$(SRCROOT)/Carthage/Build/iOS/GDPerformanceView.framework 添加到 iOS 项目中。

github "dani-gavrilov/GDPerformanceView-Swift" ~> 2.1.1

别忘了通过添加 following

import GDPerformanceView

CocoaPods

您可以使用 CocoaPodsGDPerformanceView 添加到您的 Podfile 中进行安装

platform :ios, '8.0'
use_frameworks!

target 'project_name' do
	pod 'GDPerformanceView-Swift', '~> 2.1.1'
end

别忘了通过添加 following

import GDPerformanceView_Swift

使用示例

简单开始监控。性能视图将自动添加到状态栏上方。您也可以根据需要配置外观或仅隐藏监控视图并使用其代理。

您可以在这里找到示例项目。

开始监控

默认情况下,监控是暂停的。调用以下命令开始或恢复监控:

PerformanceMonitor.shared().start()

或者:

self.performanceView = PerformanceMonitor()
self.performanceView?. start()

如果之前已隐藏,则不会显示监控视图。要显示它,请调用以下命令:

self.performanceView?.show()

暂停监控

调用以下命令暂停监控:

self.performanceView?.pause()

这不会隐藏监控视图。要隐藏它,请调用以下命令:

self.performanceView?.hide()

显示信息

您可以通过更改性能监控器的选项来更改显示的信息。

self.performanceView?.performanceViewConfigurator.options = .all

您可以从以下选项中选择:

  • 性能 - CPU 使用率和 FPS。
  • 内存 - 内存使用率。
  • 应用程序 - 应用程序版本和构建号。
  • 设备 - 设备型号。
  • 系统 - 系统名称和版本。

您也可以将它们混合使用,但顺序不重要。

self.performanceView?.performanceViewConfigurator.options = [.performance, .application, .system]

默认情况下,使用 [性能、应用程序、系统] 选项集。

您还可以使用以下方式添加您自己的自定义信息:

self.performanceView?.performanceViewConfigurator.userInfo = .custom(string: "Launch date \(Date())")

请注意,自定字符串不会自动适应屏幕,如果太长,请使用 \n

外观

您可以通过更改性能监控器的样式来改变监控视图的外观。

请调用以下命令以更改输出信息:

self.performanceView?.performanceViewConfigurator.style = .dark

您可以从以下选项中选择:

  • 暗色 - 黑色背景,白色文本。
  • 亮色 - 白色背景,黑色文本。
  • 自定义 - 您可以设置背景颜色、边框颜色、边框宽度、圆角、文本颜色和字体。

默认情况下,使用暗色样式。

您还可以覆盖 prefersStatusBarHidden 和 preferredStatusBarStyle 以满足您的期望。

self.performanceView?.statusBarConfigurator.statusBarHidden = false
self.performanceView?.statusBarConfigurator.statusBarStyle = .lightContent

交互

您可以通过手势识别器与性能视图进行交互。通过以下方式添加:

self.performanceView?.performanceViewConfigurator.interactors = [tapGesture, swipeGesture]

如果交互器为 nil 或空,则视图的 point(inside:with:) 将返回 false,使所有触摸穿透。因此,要删除交互器,只需调用以下命令:

self.performanceView?.performanceViewConfigurator.interactors = nil

默认情况下,交互器为 nil。

委托

设置委托并实现其方法。

self.performanceView?.delegate = self
func performanceMonitor(didReport performanceReport: PerformanceReport) {
	print(performanceReport.cpuUsage, performanceReport.fps, performanceReport.memoryUsage.used, performanceReport.memoryUsage.total)
}

要求

  • iOS 9.0+
  • xCode 12.0+

捐赠

想要表达感谢吗?您可以通过 Patreon 来做到。

元数据

达尼il加夫里洛夫 - VK - FB

我很高兴知道您的项目使用了这个框架。您可以向我发送一个您项目的App Store链接至我的邮箱 - [email protected]

许可协议

GDPerformanceView遵循MIT许可协议。有关更多信息,请参阅LICENSE文件。