GVKun编程网logo

SceneDelegate和AppDelegate之间的区别(delegate和appoint)

28

对于SceneDelegate和AppDelegate之间的区别感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解delegate和appoint,并且为您提供关于"AppDelegate.h

对于SceneDelegate和AppDelegate之间的区别感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解delegate和appoint,并且为您提供关于"AppDelegate.h" 和"AppDelegate.cpp" 分析、AppDelegate.h、AppDelegate.h报错、AppDelegate.m 生命周期的宝贵知识。

本文目录一览:

SceneDelegate和AppDelegate之间的区别(delegate和appoint)

SceneDelegate和AppDelegate之间的区别(delegate和appoint)

在我的SwiftUI项目中,我同时看到AppDelegate文件和SceneDelegate文件。

它们之间有什么区别?

例如,在 SceneDelegate

scene(_:willConnectTo:options:)

并在 AppDelegate

application(_:didFinishLaunchingWithOptions:)

答案1

小编典典

这两个文件旨在按整体运行应用程序所需的内容以及将支持在后台运行的一个“实例”所需的内容进行拆分。这将类似于一次配置数据库,但按窗口显示不同的值集。

您可以将它们视为全局和私有版本。一个是共享的,另一个则限于个人所有者。在某种程度上,它们正是您所期望的名称。

多窗口支持正在发生

下次创建新的Xcode项目时,您将看到AppDelegate分为两部分:AppDelegate.swift和SceneDelegate.swift。这是iPadOS附带的新的多窗口支持的结果,可以有效地将应用程序委托的工作一分为二。

从iOS 13开始,您的应用程序委托应:

  1. 设置应用程序运行期间所需的所有数据。
  2. 响应所有与应用有关的事件,例如与您共享文件。
  3. 注册外部服务,例如推送通知。
  4. 配置您的初始场景。

相比之下,场景委托在那里处理应用程序用户界面的一个实例。因此,如果用户创建了两个显示您的应用程序的窗口,则您将拥有两个场景,这两个场景均由同一个应用程序委托支持。

请记住,这些场景旨在相互独立地工作。因此,您的应用程序不再移至后台,而是将各个场景移至后台–用户可以将一个移至后台,同时保持另一个打开状态。

由https://www.hackingwithswift.com/articles/193/whats-new-in-
ios-13提供

"AppDelegate.h" 和"AppDelegate.cpp" 分析

转自 http://blog.163.com/jtyp_2000/blog/static/9910426201310893932976/


这两个文件是Cocos2d-x 游戏的通用入口文件,类似于一般 Windows 工程中主函数所在的文件。

AppDelegate 控制着游戏的生命周期,除去构造函数和析构函数外,共有3 个方法。
bool applicationDidFinishLaunching()。应用程序启动后将调用这个方法。默认的实现中已经包含了游戏启动后的必要准备:
//初始化游戏引擎控制器CCDirector,以便启动游戏引擎
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setopenGLView(&CCEGLView::sharedOpenGLView());
//启用FPS 显示,当前 FPS 会在游戏的左下角显示。FPS也就是屏幕每秒重绘的次数。即每秒帧速率。在游戏开发阶段,可以方便地确定游戏运行是否流畅。
pDirector->setdisplayStats(true);
//设置绘制间隔。绘制间隔指的是两次绘制的时间间隔,因此绘制间隔的倒数就是FPS 上限。对于移动设备来说,我们通常都会将FPS 限制在一个适当的范围内。过低的每秒重绘次数会使动画显示出卡顿的现象,而提高每秒重绘次数会导致设备运算量大幅增加,造成更高的能耗。人眼的刷新频率约为60次每秒,因此把 FPS 限定在60是一个较为合理的设置,Cocos2d-x 就把绘制间隔设置为 1/60秒。
pDirector->setAnimationInterval(1.0 / 60);
//最后是最关键的步骤,创建Hello World 场景,然后指派 CCDirector运行这个场景。对于游戏开发者而言,我们需要在此处来对我们的游戏进行其他必要的初始化,例如读取游戏设置、初始化随机数列表等。程序的最末端返回true,表示程序已经正常初始化。
CCScene *pScene = HelloWorld::scene();
pDirector->runWithScene(pScene);
void applicationDidEnterBackground()。当应用程序将要进入后台时,会调用这个方法。具体来说,当用户把程序切换到后台,或手机接到电话或短信后程序被系统切换到后台时,会调用这个方法。此时,应该暂停游戏中正在播放的音乐或音效。动作激烈的游戏通常也应该在此时进行暂停操作,以便玩家暂时离开游戏时不会遭受重大损失。
void applicationWillEnterForeground() 。该方法与applicationDidEnterBackground() 成对出现,在应用程序回到前台时被调用。相对地,我们通常在这里继续播放刚才暂停的音乐,显示游戏暂停菜单等。

AppDelegate.h

AppDelegate.h

2 IntelliSense: "MenuScene *" 类型的实参与 "cocos2d::Scene *" 类型的形参不兼容

解决:

自己在MenuScene中重写了Scene的创建方法,而appdelegate中调用的是

auto scene=MenuScene::create();

director->runWithScene(scene);

我自己的在menuScene中则是

static cocos2d::Scene* createscene();

因此会报错

只要改成这样就ok了


auto scene=MenuScene::createscene();

director->runWithScene(scene);

AppDelegate.h报错

AppDelegate.h报错

@大鸡蛋 你好,想跟你请教个问题:是否需要引入cocos2d 如果需要的话是哪个版本 当我在eclipse导入工程时报如下错误 :

Multiple markers at this line
- ''CAWindow'' in namespace ''cocos2d'' does not name a type
- Type ''CC_SYNTHESIZE_READONLY(cocos2d::CAWindow*, m_pWindow, Window)'' could not be 
resolved   这个错误是在AppDelegate.h这文文件的38行

AppDelegate.m 生命周期

AppDelegate.m 生命周期

AppDelegate.m


//
//  AppDelegate.m
//  FirstIOS
//
//  Created by MaTsonga on 14-2-23.
//  Copyright (c) 2014年 MaTsonga. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
            

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"程序已经启动...");
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"程序将要失去焦点...");
    // 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"程序已经进入后台...");
    // 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.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"程序将要进入前台...");
    // 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"程序已经获得焦点...");
    // 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.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"程序将要终止...");
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application{
    
}

@end

下面是各个不同操作的运行结果:
041940332871105.png

今天的关于SceneDelegate和AppDelegate之间的区别delegate和appoint的分享已经结束,谢谢您的关注,如果想了解更多关于"AppDelegate.h" 和"AppDelegate.cpp" 分析、AppDelegate.h、AppDelegate.h报错、AppDelegate.m 生命周期的相关知识,请在本站进行查询。

本文标签: