我使用Xcode的乐器分析我的应用程序,当我播放关卡时,我时不时地注意到帧速率下降。如果我选择帧速率下降的500ms周期,我会看到在AppDelegate中花费了275ms的时间。我没有在那里做任何特别的事 - 基本上只是样板代码。还有其他人遇到过这个问题吗?
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:.
}
}
答案 0 :(得分:0)
这很正常。应用程序委托实际上是应用程序的根对象。与UIApplication
对象本身一样,app委托是一个单例对象,并且始终存在于运行时。
app委托执行几个关键角色:
app委托的主要工作之一是响应系统报告的状态转换。对于发生的每个状态更改,系统都会调用app委托的相应方法。每个州都有不同的规则来管理应用程序应该如何运行,并且应用程序委托方法必须相应地调整应用程序的行为。
有关详细信息,请参阅此官方Apple [{3}}