swift - Today Widget - Conflict Autolayout Constraint When Locking the device -
i implementing today widget. first time getting hands onto today widget.
i created today widget programmatically without using storyboard. learned post, did: 1. change info plist 2. enable "embedded content contains swift code" 3. add @objc(hgtodayviewcontroller) after import hgtodayviewcontroller inital view controller
in loadview in hgtodayviewcontroller
var mainview:hgtodayview! override func loadview() { self.mainview = hgtodayview(frame: cgrectzero) self.view = self.mainview }
in hgtodayview:
override init(frame: cgrect) { super.init(frame: frame) // self self.translatesautoresizingmaskintoconstraints = false // subview self.tableview = uitableview() self.tableview.translatesautoresizingmaskintoconstraints = false self.addsubview(self.tableview) // constraint self.setconstraint() // debug self.tableview.backgroundcolor = uicolor.redcolor() }
in hgtodayview setconstraint method:
func setconstraint() { // self.height let selfheight = nslayoutconstraint( item: self, attribute: .height, relatedby: .equal, toitem: nil, attribute: .notanattribute, multiplier: 1, constant: 200) // avoid constraint conflict "uiview-encapsulated-layout-height" // https://stackoverflow.com/a/25795758/2581637 selfheight.priority = 999 self.addconstraint(selfheight) let viewdict = dictionary(dictionaryliteral: ("tableview", self.tableview)) let tableviewhorizontallylayout = nslayoutconstraint.constraintswithvisualformat( "|[tableview]|", options: nslayoutformatoptions.directionleadingtotrailing, metrics: nil, views: viewdict) self.addconstraints(tableviewhorizontallylayout) let tableviewverticallylayout = nslayoutconstraint.constraintswithvisualformat( "v:|[tableview]|", options: nslayoutformatoptions.directionleadingtotrailing, metrics: nil, views: viewdict) self.addconstraints(tableviewverticallylayout) }
because haven't setup table view delegate it, suspect not generate cells @ moment , displays red table view supposed do. however, if go ahead press lock button lock device, pops out conflict in constraint msg in console.
here conflict in constraint message:
2016-06-01 17:47:48.311 hgtoday[4549:462502] 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. ( "<nslayoutconstraint:0x14fd50eb0 v:|-(4)-[uiinputsetcontainerview:0x14fd5f570] (names: '|':uitexteffectswindowhosted:0x14fe6f670 )>", "<nslayoutconstraint:0x14fd6c7c0 'uiinputwindowcontroller-top' v:|-(0)-[uiinputsetcontainerview:0x14fd5f570] (names: '|':uitexteffectswindowhosted:0x14fe6f670 )>" ) attempt recover breaking constraint <nslayoutconstraint:0x14fd50eb0 v:|-(4)-[uiinputsetcontainerview:0x14fd5f570] (names: '|':uitexteffectswindowhosted:0x14fe6f670 )> make symbolic breakpoint @ uiviewalertforunsatisfiableconstraints catch in debugger. methods in uiconstraintbasedlayoutdebugging category on uiview listed in <uikit/uiview.h> may helpful. 2016-06-01 17:47:48.335 hgtoday[4549:462502] 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. ( "<nslayoutconstraint:0x14fd63780 v:|-(4)-[uiinputsetcontainerview:0x14fe70820] (names: '|':uiremotekeyboardwindowhosted:0x14fe70490 )>", "<nslayoutconstraint:0x14fd65530 'uiinputwindowcontroller-top' v:|-(0)-[uiinputsetcontainerview:0x14fe70820] (names: '|':uiremotekeyboardwindowhosted:0x14fe70490 )>" ) attempt recover breaking constraint <nslayoutconstraint:0x14fd63780 v:|-(4)-[uiinputsetcontainerview:0x14fe70820] (names: '|':uiremotekeyboardwindowhosted:0x14fe70490 )> make symbolic breakpoint @ uiviewalertforunsatisfiableconstraints catch in debugger. methods in uiconstraintbasedlayoutdebugging category on uiview listed in <uikit/uiview.h> may helpful.
this conflict in constraint seems occur when lock phone. how can solve conflict? appreciated. thank time.