setTranslatesAutoresizingMaskIntoConstraints和setFrame组合使用导致的异常
在用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组合使用导致的异常的更多相关文章
- alias导致virtualenv异常的分析和解法
		
title: alias导致virtualenv异常的分析和解法 toc: true comments: true date: 2016-06-27 23:40:56 tags: [OS X, ZSH ...
 - VS2012外接程序VMDebugger未能加载或导致了异常
		
转http://blog.csdn.net/maryhuan/article/details/42676915 故障现象:打开Visual Studio 2010后弹出错误框,外接程序VMDebugg ...
 - Fragment已经被added了导致的异常。
		
java.lang.IllegalStateException: Fragment already added: ******Effect 出现的原因是commit方法提交是异步的,所以容易出现,判 ...
 - 【原创】访问Linux进程文件表导致系统异常复位的排查记录
		
前提知识: Linux内核.Linux 进程和文件数据结构.vmcore解析.汇编语言 问题背景: 这个问题出自项目的一个安全模块,主要功能是确定某进程是否有权限访问其正在访问的文件. 实现功能时,需 ...
 - MySQL Replication--修改主键为NULL导致的异常
		
测试环境:MySQL 5.5.14/MySQL 5.6.36 测试脚本: create table tb001(id int primary key,c1 int); alter table tb00 ...
 - 第四章 TCP粘包/拆包问题的解决之道---4.2---  未考虑TCP粘包导致功能异常案例
		
4.2 未考虑TCP粘包导致功能异常案例 如果代码没有考虑粘包/拆包问题,往往会出现解码错位或者错误,导致程序不能正常工作. 4.2.1 TimeServer 的改造 Class : TimeServ ...
 - Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在
		
Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在 原因分析: 由于tomcat由7升级到8.5导致Base64的引用路径错误,默认引用为8.5中的jar, 解决方案: 修改引用 ...
 - 代码中会话同步(同步redis)导致的异常问题
		
背景: 第一天拷贝了一份tomcat(配置了redis会话同步),部署了erp-rocketmq应用(用作给顾客发送消息). 第二天早晨,整个erp系统出现异常情况: 1> ...
 - ArcGIS for Android 10.1.1API 中文标注导致程序异常崩溃问题
		
1.前言 问题:在部分Android机型中使用ArcGIS for Android 10.1.1 API 中文标注导致程序异常崩溃. 说明:手里有两台机器一台是Nexus4,原生系统,版本4.4.4, ...
 
随机推荐
- Java程序猿面试体会,还没找到工作的“猿猿们”看过来!
			
类似的话题,我大约在几个月前跟大家聊过. 这一次,我要依据这段时间的体会,再给大家整理一下. 今天,非常轻松地拿到了神州数码的offer. 尽管工资不是特别高,尽管非常多人一毕业就能进入这种公 ...
 - 取球游戏_nyoj_518(博弈-蓝桥杯原题).java
			
取球游戏 时间限制: 1000 ms | 内存限制: 65535 KB 难度: 2 描述 今盒子里有n个小球,A.B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下 ...
 - xmu 1125 越野车大赛(公式推导&&三分)(中等)
			
xmu 1125.越野车大赛 Description TheBeet正在參加一场越野车大赛.比赛的场地如右图:共分三块.每一块地面的长宽均为N与M,但地表情况不同.越野车在这段路面上的最快速度也不同. ...
 - 如何知道TSQL语句已经运行了多久
			
如何知道TSQL语句已经运行了多久 ,) --millisecond per tick --如果datediff 函数导致溢出 把下面的millisecond改为second 毫秒改为秒 SELECT ...
 - mmap 函数
			
头文件:#include <unistd.h> #include <sys/mman.h> 定义函数:void *mmap(void *start, size_t len ...
 - Python中的迭代器漫谈
			
转自:http://www.jb51.net/article/60706.htm 熟悉Python的都知道,它没有类似其它语言中的for循环, 只能通过for in的方式进行循环遍历.最典型的应用就是 ...
 - 解决ssh登录Host key verification failed
			
使用SSH登录某台机器,有时因为server端的一些变动,会出现以下信息: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: R ...
 - 微信小程序之底部弹框预约插件
			
代码地址如下:http://www.demodashi.com/demo/13982.html 一.前期准备工作: 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.c ...
 - Android程序完全退出
			
有几个activity,有一需求是在一个activityA点击back键退出系统而不是跳到之前的activity 首先想到的是清空activityA的堆栈,使用intent.setFlag ...
 - 摘:LIB和DLL的区别与在VC中的使用
			
共有两种库:一种是LIB包含了函数所在的DLL文件和文件中函数位置的信息(入口),代码由运行时加载在进程空间中的DLL提供,称为动态链接库dynamic link library.一种是LIB包含函数 ...