ios - Programmatically Setting Constraints Causes Conflict in Swift -
as posted in this github issue, having trouble hidden constraints throw error whenever try add own constraints
2016-04-18 19:22:04.270 metric time[1519:447809] unable simultaneously satisfy constraints. @ least 1 of constraints in following list 1 don't want. try this: (1) @ each constraint , try figure out don't expect; (2) find code added unwanted constraint or constraints , fix it. (note: if you're seeing nsautoresizingmasklayoutconstraints don't understand, refer documentation uiview property translatesautoresizingmaskintoconstraints) ( "<nsautoresizingmasklayoutconstraint:0x15e670e70 h=--& v=--& metric_time.view:0x15e692e70.midx == + 115>", "<nslayoutconstraint:0x15e5048c0 metric_time.view:0x15e692e70.centerx == uiview:0x15e6953e0.centerx>", "<nsautoresizingmasklayoutconstraint:0x15e55fd30 h=-&- v=-&- 'uiview-encapsulated-layout-left' h:|-(0)-[uiview:0x15e6953e0] (names: '|':uiwindow:0x15e688ed0 )>", "<nslayoutconstraint:0x15e54e750 'uiview-encapsulated-layout-width' h:[uiview:0x15e6953e0(320)]>" ) attempt recover breaking constraint <nslayoutconstraint:0x15e5048c0 metric_time.view:0x15e692e70.centerx == uiview:0x15e6953e0.centerx> make symbolic breakpoint @ uiviewalertforunsatisfiableconstraints catch in debugger. methods in uiconstraintbasedlayoutdebugging category on uiview listed in <uikit/uiview.h> may helpful.`
i have tried looking places these constraints have been created, searching viewcontroller.swift
file keywords such constraint, layout .etc turned code wrote.
my code on github if wants mess around it.
if going add constraints programmatically, need turn off translateautoresizingmaskintoconstraints. don't have enough constraints satisfy layout engine. remember uiview's don't have intrinsic size , if using auto layout view need set constraints , not rely on mixture of constraints , frames. 1 possible solution add code like:
self.view.addsubview(clockview) clockview.translatesautoresizingmaskintoconstraints = false clockview.centeryanchor.constraintequaltoanchor(self.view.centeryanchor, constant: 0.0).active = true clockview.centerxanchor.constraintequaltoanchor(self.view.centerxanchor, constant: 0.0).active = true clockview.widthanchor.constraintequaltoconstant(230.0).active = true clockview.heightanchor.constraintequaltoconstant(230.0).active = true
however not want when in landscape clock overlays label. fix playing clockview.centeryanchor.constraintequaltoanchor(self.view.centeryanchor, constant: 0.0).active = true
Comments
Post a Comment