在用Ojbect-c开发OSX应用的时候需要用到自定义控件并用代码进行布局,很自然地就使用了setTranslatesAutoresizingMaskIntoConstraints和setFrame组合,同时这个组合也很好的满足的需求。但是每当我先当前项目添加一个异常断点的时候,并开启调试程序,总是停在程序刚启动的main函数。经过debug发现是应为setTranslatesAutoresizingMaskIntoConstraints和setFrame组合导致了这个异常。

代码

[_programHeadView setTranslatesAutoresizingMaskIntoConstraints:YES];
[_programHeadView setFrame:headRect];

解决办法

在调用setTranslatesAutoresizingMaskIntoConstraints和setFrame之前先把view从父view用移除,调用之后再添加回去这样就能避免当前view的constraints和默认的constraints产生冲突。

[_programHeadView removeFromSuperview];
[_programHeadView setTranslatesAutoresizingMaskIntoConstraints:YES];
[_programHeadView setFrame:headRect];
[[[self window] contentView] addSubview:_programHeadView];

异常信息

* thread #: tid = 0x6931b, 0x00007fffb1b5745d libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #: 0x00007fffb1b5745d libobjc.A.dylib`objc_exception_throw
frame #: 0x00007fff9cde1c3d CoreFoundation`+[NSException raise:format:] +
frame #: 0x00007fff9b2a7014 AppKit`LAYOUT_CONSTRAINTS_NOT_SATISFIABLE +
frame #: 0x00007fff9b2a717e AppKit`-[NSView(NSConstraintBasedLayout) engine:willBreakConstraint:dueToMutuallyExclusiveConstraints:] +
frame #: 0x00007fff9e994fea Foundation`-[NSISEngine handleUnsatisfiableRowWithHead:body:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] +
frame #: 0x00007fff9e996006 Foundation`-[NSISEngine tryUsingArtificialVariableToAddConstraintWithMarker:rowBody:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] +
frame #: 0x00007fff9e729325 Foundation`-[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] +
frame #: 0x00007fff9e99ea01 Foundation`-[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] +
frame #: 0x00007fff9e7207ac Foundation`-[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] +
frame #: 0x00007fff9a822033 AppKit`-[NSView(NSConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:integralizationAdjustment:mutuallyExclusiveConstraints:] +
frame #: 0x00007fff9a7b68ba AppKit`-[NSView(NSConstraintBasedLayout) _constraints_didChangeAutoresizingConstraintsArrayForContainedView:] +
frame #: 0x00007fff9a83c3ed AppKit`-[NSView updateConstraints] +
frame #: 0x00007fff9a83bf27 AppKit`-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] +
frame #: 0x00007fff9a83bd31 AppKit`-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] +
frame #: 0x00007fff9a884c26 AppKit`__82-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:]_block_invoke +
frame #: 0x00007fff9e726adb Foundation`-[NSISEngine withBehaviors:performModifications:] +
frame #: 0x00007fff9a83bc33 AppKit`-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] +
frame #: 0x00007fff9b059c84 AppKit`__46-[NSView _updateConstraintsForSubtreeIfNeeded]_block_invoke +
frame #: 0x00007fff9e726adb Foundation`-[NSISEngine withBehaviors:performModifications:] +
frame #: 0x00007fff9a7b5760 AppKit`-[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] +
frame #: 0x00007fff9b059a79 AppKit`-[NSView _updateConstraintsForSubtreeIfNeeded] +
frame #: 0x00007fff9b2acbb8 AppKit`-[NSWindow(NSConstraintBasedLayout) _updateConstraintsForEngineHostingViews:] +
frame #: 0x00007fff9a884a7a AppKit`__62-[NSWindow(NSConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke +
frame #: 0x00007fff9e726adb Foundation`-[NSISEngine withBehaviors:performModifications:] +
frame #: 0x00007fff9a7b5760 AppKit`-[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] +
frame #: 0x00007fff9a88496e AppKit`-[NSWindow(NSConstraintBasedLayout) updateConstraintsIfNeeded] +
frame #: 0x00007fff9a9248fb AppKit`___NSWindowGetDisplayCycleObserver_block_invoke +
frame #: 0x00007fff9a924831 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke +
frame #: 0x00007fffa2802dc6 QuartzCore`CA::Transaction::run_commit_handlers(CATransactionPhase) +
frame #: 0x00007fffa290c8f0 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) +
frame #: 0x00007fffa28018a1 QuartzCore`CA::Transaction::commit() +
frame #: 0x00007fff9ac07b99 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke. +
frame #: 0x00007fff9ccf8dd7 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ +
frame #: 0x00007fff9ccf8d47 CoreFoundation`__CFRunLoopDoObservers +
frame #: 0x00007fff9ccd9789 CoreFoundation`__CFRunLoopRun +
frame #: 0x00007fff9ccd91c4 CoreFoundation`CFRunLoopRunSpecific +
frame #: 0x00007fff9c23aebc HIToolbox`RunCurrentEventLoopInMode +
frame #: 0x00007fff9c23abf9 HIToolbox`ReceiveNextEventCommon +
frame #: 0x00007fff9c23ab26 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter +
frame #: 0x00007fff9a7d5e24 AppKit`_DPSNextEvent +
frame #: 0x00007fff9af5185e AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] +
frame #: 0x00007fff9a7ca7ab AppKit`-[NSApplication run] +
frame #: 0x00007fff9a7951de AppKit`NSApplicationMain +

setTranslatesAutoresizingMaskIntoConstraints和setFrame组合使用导致的异常的更多相关文章

  1. alias导致virtualenv异常的分析和解法

    title: alias导致virtualenv异常的分析和解法 toc: true comments: true date: 2016-06-27 23:40:56 tags: [OS X, ZSH ...

  2. VS2012外接程序VMDebugger未能加载或导致了异常

    转http://blog.csdn.net/maryhuan/article/details/42676915 故障现象:打开Visual Studio 2010后弹出错误框,外接程序VMDebugg ...

  3. Fragment已经被added了导致的异常。

    java.lang.IllegalStateException: Fragment already added:  ******Effect 出现的原因是commit方法提交是异步的,所以容易出现,判 ...

  4. 【原创】访问Linux进程文件表导致系统异常复位的排查记录

    前提知识: Linux内核.Linux 进程和文件数据结构.vmcore解析.汇编语言 问题背景: 这个问题出自项目的一个安全模块,主要功能是确定某进程是否有权限访问其正在访问的文件. 实现功能时,需 ...

  5. MySQL Replication--修改主键为NULL导致的异常

    测试环境:MySQL 5.5.14/MySQL 5.6.36 测试脚本: create table tb001(id int primary key,c1 int); alter table tb00 ...

  6. 第四章 TCP粘包/拆包问题的解决之道---4.2--- 未考虑TCP粘包导致功能异常案例

    4.2 未考虑TCP粘包导致功能异常案例 如果代码没有考虑粘包/拆包问题,往往会出现解码错位或者错误,导致程序不能正常工作. 4.2.1 TimeServer 的改造 Class : TimeServ ...

  7. Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在

    Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在 原因分析: 由于tomcat由7升级到8.5导致Base64的引用路径错误,默认引用为8.5中的jar, 解决方案: 修改引用 ...

  8. 代码中会话同步(同步redis)导致的异常问题

    背景: 第一天拷贝了一份tomcat(配置了redis会话同步),部署了erp-rocketmq应用(用作给顾客发送消息).            第二天早晨,整个erp系统出现异常情况: 1> ...

  9. ArcGIS for Android 10.1.1API 中文标注导致程序异常崩溃问题

    1.前言 问题:在部分Android机型中使用ArcGIS for Android 10.1.1 API 中文标注导致程序异常崩溃. 说明:手里有两台机器一台是Nexus4,原生系统,版本4.4.4, ...

随机推荐

  1. (剑指Offer)面试题55:字符流中第一个不重复的字符

    题目: 请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读出前 ...

  2. T-SQL with关键字

    T-SQL with关键字   Select字句在逻辑上是SQL语句最后进行处理的最后一步,所以,以下查询会发生错误: SELECT YEAR(OrderDate) AS OrderYear, COU ...

  3. java线程同步问题——由腾讯笔试题引发的风波

    刚刚wm问我了一道线程的问题,因为自己一直是coder界里的渣渣.所以就须要恶补一下. 2016年4月2号题目例如以下. import java.util.logging.Handler; /** * ...

  4. leetCode 45.Jump Game II (跳跃游戏) 解题思路和方法

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

  5. 【PAT】1028. List Sorting (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...

  6. js 多级联动(省、市、区)

      js 多级联动(省.市.区) CreateTime--2018年4月9日17:10:38 Author:Marydon 方式一: 数据从数据库获取,ajax实现局部刷新 方式二: 数据从json文 ...

  7. 30、Arrays工具类

    1.查询元素 int binarySearch(type[] a,type key):使用二分法查询key元素值在a数组中出现的索引:如果a数组不包含key元素,则返回负数.调用该方法时要求数组中元素 ...

  8. linux命令创建和修改用户及密码

    linux下创建用户 1.添加ftp用户 useradd ftpname -d /home/ftp passwd ftppwd 以下操作都以root权限进行: service vsftpd start ...

  9. log4cpp基础测试

    // log4cplus.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h" #include <iostream>#include ...

  10. CString中Format函数与格式输入与输出

    CString中Format函数与格式输入与输出 Format是一个非经常常使用.却又似乎非常烦的方法,下面是它的完整概貌.以供大家查询之用:   格式化字符串forma("%d" ...