在用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 +

最新文章

  1. centos7 开放端口
  2. [MySQL5.6 新特性] 全局事务标示符(GTID)
  3. HTML5系列五(Canvas详述)
  4. 学生管理系统-火车订票系统 c语言课程设计
  5. mysql控制流程函数
  6. linux----ln
  7. NYOJ 7-街区最短路径问题(曼哈顿距离)
  8. for循环中一个不容小觑的问题
  9. 加州理工大学公开课:机器学习与数据挖掘_线性模型 II(第IX类)
  10. LeetCode OJ 122. Best Time to Buy and Sell Stock II
  11. IOS @proporty 关键字(一)retain strong
  12. 02_3中方式的反射,通过Class.forName获得Class对象,通过类.class获得字节码对象,通过类实例.getClass()的方式获得Class对象
  13. Pc与移动端的测试异同性
  14. 基础知识:IDE集成开发环境(pycharm)、基本数据类型、用户的交互、运算符
  15. C# 微信开发-----微信会员卡(三)激活会员卡
  16. JQ方法实用案例///鼠标移动到div和修改ipt中弹窗、CSS鼠标变小手、JQ获取元素属性、JQ选择器
  17. python3之编码详解
  18. draftsight的热补丁
  19. scp拷贝提示its a directory 错误
  20. MyEclipse2014配置Tomcat开发JavaWeb程序JSP以及Servlet

热门文章

  1. 文件同步程序,Python和C写的DLL
  2. 用thinkphp操作session
  3. OpenMeetings(4)----新用户注册
  4. RootMotionComputer 根运动计算机
  5. HashMap源代码阅读
  6. webpack CommonsChunkPlugin 提取公共代码
  7. javascript 面向对象编程(工厂模式、构造函数模式、原型模式)
  8. 用python实现的的手写数字识别器
  9. C与C++中非常少犯的错误,犯了后却非常难找出的错误
  10. 老生常谈combobox和combotree模糊查询