是的,我知道子类化 UIWindow 不受欢迎,但我的子类化 UIWindow 仅用于调试目的(一旦检测到特定的运动事件,它就会截取当前页面的屏幕截图)。
无论如何,我在项目的Build Settings 中创建了一个名为DEBUG
的自定义预编译器标记,但我无法正确加载/运行它。现在,它没有截取屏幕截图,但它正在记录运动事件的发生。
这是我在 AppDelegate 的 didFinishLaunchingWithOptions:
#if DEBUG
DebugWindow *debugWindow = [[DebugWindow alloc] init];
self.window = debugWindow; //'window' is declared in the AppDelegate's @interface file and synthesized as window=_window in the @implementation file
#else
self.window = _window;
#endif
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
最佳答案
调试标志的使用方法
#if DEBUG == 1
#define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
#define MARK CMLog(@"%s", __PRETTY_FUNCTION__);
#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
#else
#define CMLog(format, ...)
#define MARK
#define START_TIMER
#define END_TIMER(msg)
#endif
这是截图
同样在发布设置中将标志设置为 0 像这样 -DDEBUG=0
这样你就可以实现你想要实现的目标。让我知道它是否有帮助。
关于objective-c - 子类化 UIWindow - 需要预处理器帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6784852/