{"action":"created","issue":{"url":"https://api.github.com/repos/SnapKit/SnapKit/issues/168","labels_url":"https://api.github.com/repos/SnapKit/SnapKit/issues/168/labels{/name}","comments_url":"https://api.github.com/repos/SnapKit/SnapKit/issues/168/comments","events_url":"https://api.github.com/repos/SnapKit/SnapKit/issues/168/events","html_url":"https://github.com/SnapKit/SnapKit/issues/168","id":116054096,"number":168,"title":"snp_updateConstraints adds a second constraint instead of updating (only changing the offset)","user":{"login":"ThomasCle","id":1969572,"avatar_url":"https://avatars.githubusercontent.com/u/1969572?v=3","gravatar_id":"","url":"https://api.github.com/users/ThomasCle","html_url":"https://github.com/ThomasCle","followers_url":"https://api.github.com/users/ThomasCle/followers","following_url":"https://api.github.com/users/ThomasCle/following{/other_user}","gists_url":"https://api.github.com/users/ThomasCle/gists{/gist_id}","starred_url":"https://api.github.com/users/ThomasCle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThomasCle/subscriptions","organizations_url":"https://api.github.com/users/ThomasCle/orgs","repos_url":"https://api.github.com/users/ThomasCle/repos","events_url":"https://api.github.com/users/ThomasCle/events{/privacy}","received_events_url":"https://api.github.com/users/ThomasCle/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-10T07:38:51Z","updated_at":"2015-11-10T11:43:46Z","closed_at":"2015-11-10T11:43:46Z","body":"I am trying to update the offset of a top-constraint on `scrollViewDidScroll:`\r\n\r\nFirst I add the constraints I need in `viewDidLoad:`:\r\n\r\n    self.myView!.snp_makeConstraints(closure: { (make) -> Void in\r\n         make.width.equalTo(self.tableView)\r\n         make.top.equalTo(self.tableView).offset(0)\r\n         make.height.greaterThanOrEqualTo(self.myView!.headerHeight)\r\n    })\r\n\r\nThen I try to update the top-constraint in `scrollViewDidScroll:`:\r\n\r\n    self.myView!.snp_updateConstraints(closure: { (make) -> Void in\r\n        make.top.equalTo(self.tableView).offset(-scrollView.contentOffset.y)\r\n    })\r\n\r\nWhen I try to do so, I get the following error:\r\n> Unable to simultaneously satisfy constraints.\r\n\tProbably at least one of the constraints in the following list is one you don't want. \r\n\tTry this: \r\n\t\t(1) look at each constraint and try to figure out which you don't expect; \r\n\t\t(2) find the code that added the unwanted constraint or constraints and fix it. \r\n(\r\n    \"SnapKit.LayoutConstraint:0x7fe050ce62c0@/path/to/app/HeaderTableViewController.swift#93 App.CenteringTableHeaderView:0x7fe050fcdd40.top == UITableView:0x7fe05110e400.top + 183.0\",\r\n    \"SnapKit.LayoutConstraint:0x7fe050cf4410@/path/to/app/HeaderTableViewController.swift#50 App.CenteringTableHeaderView:0x7fe050fcdd40.top == UITableView:0x7fe05110e400.top\"\r\n)\r\n\r\n> Will attempt to recover by breaking constraint \r\nSnapKit.LayoutConstraint:0x7fe050ce62c0@/path/to/app/HeaderTableViewController.swift#93 App.CenteringTableHeaderView:0x7fe050fcdd40.top == UITableView:0x7fe05110e400.top + 183.0\r\n\r\n> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.\r\nThe methods in the UIConstraintBasedLayoutDebugging category on UIView listed in UIKit/UIView.h may also be helpful.\r\n\r\nAs you can see, it looks like the top-constraint gets added with the offset, instead of updating the offset of the existing constraint.\r\n\r\nI have had this working with `NSLayoutConstraint` without any problem, but I want to use SnapKit instead:\r\n\r\n    self.constraintViewTop = NSLayoutConstraint(item: self.tableView, attribute: .Top, relatedBy: .Equal, toItem: self.myView, attribute: .Top, multiplier: 1.0, constant: 0.0)\r\n    self.tableView.addConstraint(self.constraintViewTop!)\r\n\r\nAnd then changing the offset by:\r\n\r\n     self.constraintViewTop?.constant = -scrollView.contentOffset.y;\r\n\r\n\r\nAm I using the \"offset\" wrong or how can I achieve this with SnapKit?"},"comment":{"url":"https://api.github.com/repos/SnapKit/SnapKit/issues/comments/155397879","html_url":"https://github.com/SnapKit/SnapKit/issues/168#issuecomment-155397879","issue_url":"https://api.github.com/repos/SnapKit/SnapKit/issues/168","id":155397879,"user":{"login":"ThomasCle","id":1969572,"avatar_url":"https://avatars.githubusercontent.com/u/1969572?v=3","gravatar_id":"","url":"https://api.github.com/users/ThomasCle","html_url":"https://github.com/ThomasCle","followers_url":"https://api.github.com/users/ThomasCle/followers","following_url":"https://api.github.com/users/ThomasCle/following{/other_user}","gists_url":"https://api.github.com/users/ThomasCle/gists{/gist_id}","starred_url":"https://api.github.com/users/ThomasCle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThomasCle/subscriptions","organizations_url":"https://api.github.com/users/ThomasCle/orgs","repos_url":"https://api.github.com/users/ThomasCle/repos","events_url":"https://api.github.com/users/ThomasCle/events{/privacy}","received_events_url":"https://api.github.com/users/ThomasCle/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T11:43:46Z","updated_at":"2015-11-10T11:43:46Z","body":"Oops, sorry for the inconvenience. It looks like I accidentally had moved the `snp_makeConstraints` to `viewDidLayoutSubviews` instead of `viewDidLoad:`.\r\n\r\nIt works perfectly now. Thank you for the example. It helped me to spot the problem."}}