1

是的,我知道子类化 UIWindow 是不受欢迎的,但我的子类化 UIWindow 仅用于调试目的(一旦检测到特定的运动事件,它会截取当前页面的屏幕截图)。

DEBUG无论如何,我在我的项目的Build Settings中创建了一个自定义预编译器标志,但是我在让它正常加载/运行时遇到了问题。现在,它不是截取屏幕截图,而是记录运动事件的发生。

这是我在 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];
4

1 回答 1

0

以下是如何使用调试标志

#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

这样您就可以实现您想要实现的目标。让我知道它是否有帮助。

于 2011-07-23T03:53:43.900 回答