Re: [問題] Autolayout使用問題
※ 引述《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
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.160.116.75
※ 編輯: whitefur 來自: 118.160.116.75 (02/12 10:14)
推
02/12 12:25, , 1F
02/12 12:25, 1F
→
02/12 12:26, , 2F
02/12 12:26, 2F
→
02/12 12:26, , 3F
02/12 12:26, 3F
NSLayoutConstraint *constraint =
[NSLayoutConstraint constraintWithItem:self.tableView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
^^^^^^
Top才對
因為是superview的top跟tableView對齊
multiplier:1.0
constant:0.0f];
※ 編輯: whitefur 來自: 61.230.125.241 (02/12 16:18)
※ 編輯: whitefur 來自: 61.230.125.241 (02/12 16:18)
※ 編輯: whitefur 來自: 61.230.125.241 (02/12 16:19)
推
02/13 22:29, , 4F
02/13 22:29, 4F
→
02/13 22:30, , 5F
02/13 22:30, 5F
→
02/13 22:30, , 6F
02/13 22:30, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章