gpt4 book ai didi

ios - SpriteKit 游戏在 AppDelegate 中花费大量时间

转载 作者:行者123 更新时间:2023-11-28 08:35:34 24 4
gpt4 key购买 nike

我正在使用 Xcode 的 Instruments 分析我的应用程序,当我玩关卡时,我注意到帧率时不时地下降。如果我选择帧速率下降的 500 毫秒时间段,我会看到 AppDelegate 花费了 275 毫秒的时间。我在那里没有做任何特别的事情——基本上只是样板代码。还有其他人遇到过这个问题吗?

Running Time    Self (ms)   Symbol Name

275.0ms 100.0% 258.0 main

这是我的 AppDelegate 代码:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
print("about to enter background")
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
print("entered background")
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
print("will become active")
//NSNotificationCenter.defaultCenter().postNotificationName("PauseGame", object: self)
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

最佳答案

这很正常。应用委托(delegate)实际上是您应用的根对象。与 UIApplication 对象本身一样,app delegate 是一个单例对象,并且始终存在于运行时。

应用委托(delegate)执行几个关键角色:

  • 它包含您应用的启动代码。
  • 它会响应应用状态的关键变化。具体来说,它响应临时中断和变化您的应用程序的执行状态,例如当您的应用程序从前景到背景。
  • 它响应来自应用外部的通知,例如作为远程通知(也称为推送通知),内存不足警告、下载完成通知等。
  • 它确定是否应该进行状态保存和恢复并根据需要协助保存和修复过程。
  • 它响应以应用本身为目标的非特定事件到您应用的 View 或 View Controller 。

app delegate 的主要工作之一是响应系统报告的状态转换。对于发生的每个状态更改,系统都会调用应用程序委托(delegate)的适当方法。每个状态都有不同的规则来管理应用程序的预期行为,应用程序委托(delegate)方法必须相应地调整应用程序的行为。

更多信息请看苹果官方guide

关于ios - SpriteKit 游戏在 AppDelegate 中花费大量时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37859392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com