objective-c - 子类化 UIWindow - 需要预处理器帮助

标签 objective-c ios cocoa-touch subclass uiwindow

是的,我知道子类化 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

这是截图

enter image description here

同样在发布设置中将标志设置为 0 像这样 -DDEBUG=0

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

关于objective-c - 子类化 UIWindow - 需要预处理器帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6784852/

相关文章:

ios - 存在 Xib 文件的自定义绘图

cocoa-touch - iOS5 : Has somebody managed to fix UIAlertView with three buttons and textfield (UIAlertViewStylePlainTextInput)?

objective-c - Objective-C 中的 Swift 单例访问触发 EXC_BAD_INSTRUCTION (EXC_I386_INVOP)

ios - 为什么我的通知事件未在Cordova中触发?

ios - iOS 中的电话簿

ios - 应用内购买获得 App Store 促销批准需要多长时间?

ios - MPRemoteCommandCenter 控制中心暂停按钮即使在音频文件暂停后也不会更新

ios - 在不同的 View Controller 中显示用户操作的结果

objective-c - 当用户键入文本时为文本着色(iOS、Xcode)

objective-c - 在另一个类的应用程序委托(delegate)中使用 NSMutableArray