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, ...
随机推荐
- 阅读jQuery源代码带给我们的18个惊喜
相信大家都非常熟悉jQuery类库,绝对最受欢迎的JS框架,如果你也有兴趣阅读v源代码的话,或者你也会有同感. 以下便是阅读jQuery源代码后挖掘的18条令人惊奇的信息: 原文:阅读jQuery源代 ...
- system返回值校验
int xsystem(const char *cmd){ int err; err = system(cmd); if (err == -1) { fprintf(stderr, &qu ...
- UVA 270 Lining Up (几何 判断共线点)
Lining Up ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...
- html5图像、图片处理【转】
本文主题 情人节在网上看到国外JS牛人利用HTML5技术实现的一朵玫瑰花,深切的感受到HTML5技术的强大.本着学习的态度看了一下那朵玫瑰花的源代码,其中用到的HTML5技术是canvas标签,于是灵 ...
- UNIX网络编程调试工具:tcpdump、netstat和lsof
tcpdump程序 tcpdump一边从网络读入分组一边显示关于这些分组的大量信息.它还能够只显示与所指定的准则匹配的那些分组. netstat程序 netstat服务于多个目的: (1)展示网络端点 ...
- HTTP请求头 If-Modified-Since
来自:http://www.jm47.com/g/91174.htm 一直以来没有留意过HTTP请求头的IMS(If-Modified-Since)标签. 最近在分析Squid的access.log日 ...
- Python 正则表达式学习摘要及资料
来源:Michael_翔_ 摘要 在正则表达式中,如果直接给出字符,就是精确匹配. {m,n}? 对于前一个字符重复 m 到 n 次,并且取尽可能少的情况 在字符串'aaaaaa'中,a{2,4} 会 ...
- 30、Arrays工具类
1.查询元素 int binarySearch(type[] a,type key):使用二分法查询key元素值在a数组中出现的索引:如果a数组不包含key元素,则返回负数.调用该方法时要求数组中元素 ...
- C/S和B/S 赞美创新,好酸啊。
似乎是一个很古老的话题啊...翻出来炒冷饭也是很有趣的. 昨天聊iDempiere时说到了Client这个词,我和人家说我依然会条件反射般想到了C/S,从而又SB般感慨了一番世风日下,人心不古.... ...
- ASP.NET给DataGrid,Repeater等添加全选批量删除等功能
很多情况下,在管理或者查看列表的时候我们需要很需要“全选”这个功能,这在ASP.NET中是非常容易实现的,下面我就将演示一点小代码实现这一功能. 实现全选的还是js的一个小函数: [code] ...