YXTUnsatisfiableConstraintsDetector 0.2.0

YXTUnsatisfiableConstraintsDetector 0.2.0

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布上次发布2016年2月

Tom Elliott维护。



  • Tom Elliott

这是一个调试工具,它会在控制台捕获无法满足的约束错误,并提供回调,可以是直接到块或通过 NSNotificationCenter。这允许在运行时处理此类错误。

这个工具仅用于调试,并没有为生产级别的性能而设计。

使用案例

  • 在开发过程中直观地突出显示约束问题
  • 在单元测试期间捕获约束问题
  • 在收到约束错误时通过终止应用程序来使 UI 测试失败。

示例项目

要运行示例项目,克隆仓库,然后首先从 Example 目录运行 pod install

示例项目显示了使用检测器突出显示具有无法满足的约束的 UIViews 的用法,在有问题视图中显示红色边框。

需求

YXTUnsatisfiableConstraintsDetector 支持 iOS 7 及以上版本的工程项目。

安装

手动安装

要手动安装,请将 Pod/Classes 目录下的文件复制到您的项目中。

使用

要将检测器导入到指定的源文件中

#import "YXTUnsatisfiableConstraintsDetector.h"

然后,您可以实例化一个 YXTUnsatisfiableConstraintsDetector 实例,并使用 registerBlock: 方法添加回调块。在配置好所有块后,调用 beginMonitoring 以开始监听错误。

建议在 AppDelegate 的启动方法中创建单个 YXTUnsatisfiableConstraintsDetector 实例,并将其放在 DEBUG 检查中,以确保它不在发布构建中调用。例如,要注册一个标记有错误的红色视图的回调

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef DEBUG
    YXTUnsatisfiableConstraintsDetector *detector = [[YXTUnsatisfiableConstraintsDetector alloc] init];
    [detector registerBlock:^(UIView *view){
        if(view != nil){
            dispatch_async(dispatch_get_main_queue(), ^(void){
                view.layer.borderColor = [UIColor redColor].CGColor;
                view.layer.borderWidth = 3.0;
            });
        }
    }];
    [detector beginMonitoring];
#endif
    return YES;
}

注意,如果问题 UIView 当前不在视图层次结构中,则 view 可能为 null。

作者

Tom Elliott,[email protected]

许可

YXTUnsatisfiableConstraintsDetector 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。