Re: [問題] Autolayout使用問題

作者: whitefur (白毛)   2014-02-12 09:59:54
※ 引述《kiii210 (JohnnyChian)》之銘言:
: 大家好,上來請教一下各位高手...小弟在Autolayout使用上一直都很有困難
: 現在是用StoryBoard拉Autolayout
: 畫面上有一個 "searchBar" 跟 "tableView" 排列方式如圖
: http://i.imgur.com/RrlzpSr.png
: searchBar的constraint是Bottom Space to tableView, 距離0
: tableView的constraint是Top Space to tableView, 距離0
: 另外也有Leading space 跟 Trailing Space to Superview, 距離也都是0
: 現在有個需求, 有某個狀況會要把searchBar從畫面中移除(removeFromSuperView)
: 而我想要在searchBar移除之後讓tableView的Top Space to Superview 是 0
: 簡單的說就是searchBar移除之後, tableView要往上遞補..
: 不過一直試不出來, 也不知道constraint怎麼設比較好
: 不知道searchBar移除之後, 該怎麼讓autolayout知道我想重新layout @@
: 麻煩一下各位高手了 謝謝
設一個讓tableView的top跟superview的bottuom距離為0的constraint即可
^^^^我寫錯了,是top
[self.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[tableView]"
options:0
metrics:nil
views:@{@"tableView": _tableView}]];
我寫了一個簡單的Demo
https://github.com/WhiteFur/AutolayoutPractice
作者: kiii210 (HelloWorld!)   2014-02-12 12:25:00
感謝您,成功了,我之前也是這樣想...但不是用visualFormat我這樣寫:http://goo.gl/hN2Fa7,意思應該一樣呀?怎麼會這個就不成功..疑惑..謝謝...我以為是要跟superview的bottom對齊=_=tableview上面跟superview的下面距離是0^以為是

Links booklink

Contact Us: admin [ a t ] ucptt.com