【发布时间】:2017-01-31 13:30:20
【问题描述】:
我有一个自定义的UITableViewCell,里面有UITextView、UICollectionView 和UITableView。它们之间有 10 px 的空间。在某些情况下,我只有UITextView,有时只有集合视图等。
当没有文本时 - 我必须将 UICollection 视图向上移动 10 像素。如果我没有文本,tableView 和 collectionView 它应该是零高度。
- (void)configureMiddleWrapperState
{
self.middleWrapperHasNote = self.noteTextView.text.length > 0;
self.noteTextViewTopConstraint.constant = self.middleWrapperHasNote ? 7.f : 0.f;
self.staffWrapperTopConstraint.constant = self.middleWrapperHasStaff ? 7.f : 0.f;
self.tagsWrapperTopConstraint.constant = self.middleWrapperHasTags ? 7.f : 0.f;
BOOL middleWrapperHasAtleastOne = self.middleWrapperHasNote || self.middleWrapperHasStaff ||
self.middleWrapperHasTags;
self.middleWrapperLastTenPixelSpaceConstraint.constant = middleWrapperHasAtleastOne ? 7.f : 0.f;
[self setNeedsUpdateConstraints];
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self setExcludedPaths];
[self configureMiddleWrapperState];
}
只有当我多次上下滚动时,约束才会起作用。
【问题讨论】:
标签: ios objective-c uitableview constraints ios-autolayout