PureLayoutを使用しています
ちなみに、私はすべてのレイアウトをコードで行っています。
UIScrollView
Facebook のニュース フィードのように機能する があります。私のスクロールビューにはいくつかのサブビューがあります。それらを「カード」と呼びましょう。
内部に制約をupdateConstraints
次のように設定しました。
for (i, view) in enumerate(self.viewsForAutoLayout) {
/** Set view dimension **/
view.autoSetDimension(ALDimension.Width, toSize: view.frame.width)
view.autoSetDimension(ALDimension.Height, toSize: view.frame.height)
/** Make 'em stack **/
if i == 0 {
view.autoPinEdgeToSuperviewEdge(
ALEdge.Top,
withInset: offset
)
} else {
view.autoPinEdge(
ALEdge.Top,
toEdge: ALEdge.Bottom,
ofView: self.viewsForAutoLayout[i - 1],
withOffset: offset
)
}
}
self.setNeedsLayout()
ではlayoutSubviews
、ここでカードのサイズを変更します。イメージがインターネットからロードされた後、それぞれの高さが更新されます (NSURLConnection.sendAsynchronousRequest
参考までに、このトピックとは関係ありません)。その後、自分scrollView
の高さを更新します。
for (i, view) in enumerate(self.viewsForAutoLayout) {
view.realignContent()
}
totalHeight += view.frame.size.height + offset
let size = CGSizeMake(AppConstants.ScreenSize.SCREEN_WIDTH, totalHeight)
self.scrollView.resizeContent(size) // extension
問題は、それらが適切に調整されていないことです。それは、コンテンツをまったく整列させない呼び出しのようなものですsetNeedsLayout()
(最終的には呼び出しますlayoutSubviews()
-間違っていたら訂正してください)。setNeedsUpdateConstraints()
また、それが呼び出されることも確認しました。
私はこれを呼び出してみましたlayoutSubviews
...
view.autoSetDimension(ALDimension.Height, toSize: view.frame.height)
...しかし、ある種の警告が表示されます:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this: (1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand,
refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x1700918a0 V:[XXX.ContentBox:0x15fd63a80(928.986)]>",
"<NSLayoutConstraint:0x170098bf0 V:[XXX.ContentBox:0x15fd63a80(1275.99)]>"
)
(カードContentBox
は私のものです)UIView
カードがぐちゃぐちゃに見えます。カードを正しく整列させるにはどうすればよいですか?
質問の理解に役立つ場合は、コードに関するサイドコメントに喜んでお答えします。:) 側面の提案も悪くありません。