xcode 覆盖.mm扩展名中的UIViewController方法

6jjcrrmo  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(72)

我正在尝试为Game Maker做一个扩展:当从屏幕顶部拖动时禁用通知栏的Studio。
扩展名是.mm和.h文件的组合。
我想使用这个post中描述的解决方案,但我不熟悉Objective C++,也不确定那里引用的方法的范围/用法。
NotificationBar.h

@interface NotificationBar : NSObject
{
}
@end

字符串
NotificationBar.mm

#include <UIKit/UIKit.h>

@implementation NotificationBar
- (void)viewDidLoad {
    [super viewDidLoad];

    if (@available(iOS 11.0, *)) { 
      [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
    }
 }

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    return UIRectEdgeAll;
}
@end


此代码给出错误'NotificationBar' cannot use 'super' because it is a root class。有没有一种方法可以从.mm扩展名覆盖这些方法?

nwo49xxi

nwo49xxi1#

从您的代码和链接来看,您似乎希望NotificationBar成为UIViewController。在这种情况下,您需要声明。我相信这是你想要的标题:

#import <UIKit/UIKit.h>

@interface NotificationBar : UIViewController
@end

字符串
在你的.mm文件中,你可以这样写:

#import "NotificationBar.h"

@implementation NotificationBar

... Your existing overrides ...

... The rest of this class; otherwise this isn't going to do much ...
@end


我对Game Maker Studio一无所知,但请记住,您所写的只是定义了一个名为NotificationBar的新类。它没有扩展现有的类,如果GMS已经定义了一个名为NotificationBar的ObjC类,它将产生冲突。如果您想扩展GMS定义的内容,则需要研究GMS如何允许这样做。没有普遍的答案。(有GMS经验的人可能会在这里提供更多帮助。

相关问题