- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试修改 UICollectionViewFlowLayout
(垂直滚动),以便将每个部分标题放置在该部分所有项目的左侧(而不是顶部,这是默认设置)。
也就是说,这是默认行为:
...这就是我想要的:
所以我继承了 UICollectionViewFlowLayout
:
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
guard let attributesToReturn = super.layoutAttributesForElementsInRect(rect) else {
return nil
}
// Copy to avoid the dreadded "Cached frame mismatch" runtime warning:
var copiedAttributes = [UICollectionViewLayoutAttributes]()
for attribute in attributesToReturn {
copiedAttributes.append(attribute.copy() as! UICollectionViewLayoutAttributes)
}
for attributes in copiedAttributes {
if let kind = attributes.representedElementKind {
// Non nil: It is a supplementary View
if kind == UICollectionElementKindSectionHeader {
// HEADER
var frame = attributes.frame
frame.origin.y = frame.origin.y + frame.size.height
frame.size.width = sectionInset.left
attributes.frame = frame
}
}
else{
// Nil: It is an item
}
}
return copiedAttributes
}
另外,为了好的措施(?),我采用了协议(protocol) UICollectionViewDelegateFlowLayout
并实现了这个方法 (虽然不清楚什么优先。然后,有设置在 Storyboard文件,但那些似乎被它们的运行时副本覆盖了):
func collectionView(
collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForHeaderInSection section: Int) -> CGSize {
let left = (collectionViewLayout as! UICollectionViewFlowLayout).sectionInset.left
return CGSizeMake(left, 1)
}
...我成功地将标题降低到其部分的第一行;但是,标题最初占用的空间保持打开状态:
...我能做到这一点的唯一方法是将标题 View 高度设置为 1
并将“Clips Subviews”设置为 false,以便显示标签(如果我设置高度为 0,标签不被绘制),但这绝对不是最优雅的解决方案(并且可能会闯入 - 比如说 - iOS 9.2)
也就是说,页眉的实际高度链接到部分之间的垂直空间:我不能将空间设置为零,同时保持页眉 View 的显示尺寸合理。
也许我还应该将所有部分项目向上移动(与我的标题高度相同的量)来填补这个洞?
最佳答案
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];
NSMutableArray *allAttributes = [NSMutableArray new];
for (UICollectionViewLayoutAttributes* attributes in originalAttributes) {
[allAttributes addObject:[attributes copy]];
}
for (UICollectionViewLayoutAttributes *attributes in allAttributes) {
NSString *kind = attributes.representedElementKind;
if (kind == UICollectionElementKindSectionHeader) {
CGRect frame = attributes.frame;
UICollectionViewLayoutAttributes *cellAttrs = [super layoutAttributesForItemAtIndexPath:attributes.indexPath];
frame.origin.x = frame.origin.x;
frame.size.height = self.sectionInset.top;
frame.size.width = cellAttrs.frame.size.width;
attributes.frame = frame;
}
}
return allAttributes;
}
关于ios - UICollectionViewFlowLayout 将节标题放在左插图部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32990605/
我有一个 png 文件 (1603px x 75px),我想将其用作某个部分的边框。但我希望它出现在内部(插图)而不是外部。但我无法弄清楚如何使边框图像恰好进入(插入)图像高度,而不会使图像的垂直尺寸
UIViewController ContainerView -> UITableViewController界面 View ContainerView -> UIViewController 当显示
我正在努力使我的标题具有漂亮的浮雕外观。它在 Chrome 中运行良好,但 Firefox 退出了。我怎样才能使这种效果在两者中都起作用?这是 fiddle : https://jsfiddle.ne
我有一个包含按钮的 UIBarButtonItem,我在该按钮上为按下/未按下状态设置了自定义背景图像。按下的图像向下移动 4px,因此未按下时的文本看起来垂直居中。我知道我可以使用 [button
uitabbarcontroller子类 隐藏/删除原始选项卡栏 将自定义视图置于uitabbarcontroller视图的底部 uitabbarcontroller->uiviewcontrolle
我试图在一个简单的客户端-服务器程序中说明 Nagle 算法。但我不太明白,也无法将其清楚地打印给我。 在我的示例中,客户端只是生成从 1 到 1024 的整数并将它们发送到服务器。服务器只是将这些
我正在使用 Netbeans GUI,我想在 jTextField 的开头添加 3 个像素的空间: 我已经尝试在 GUI 中使用 setMargin 和 setInset,但它没有改变任何东西。 我还
有没有办法使用 CSS3 在文本输入框上获得插入/内部阴影?下面的插入代码只会做盒子 -moz-box-shadow:inset 0 0 10px #000000; box-shadow:i
我正在对 CSS3 的新功能进行一些测试,但这种组合仅适用于最新版本的 Chrome 和 Firefox,但不适用于 Safari 或 Opera: box-shadow: inset
我想像这样使用 CSS3 获得文本字段效果:- 我尝试使用 CSS3 做到这一点,但未能获得完全相同的外观,请在 jsfiddle.net 中找到我的代码 CSS .field { -webkit-b
我正在使用 knitr::rmarkdown (但 knitr::knitr 和我的 VignetteEngine 一样) .然后我使用 devtools::build_vignettes() 构建我
我有一个具有固定布局边距的 StackView,为所有子元素提供左侧和右侧的边距。这对于大多数子元素(如标签等)非常有用。但是,我还有一个 tableView 作为子元素,它为单元格(例如字幕原型(p
我注意到来自 iPhone 专用应用程序和 Apple Watch 兼容应用程序的推送通知之间存在差异,我希望我的 Watch 兼容应用程序显示与普通 iPhone 专用应用程序推送通知类似的通知。
我正在尝试使用 d3.js 绘制 map ,该 map 具有城市 map 的一部分偏移并绘制在不同的位置( map 插图)。有使用 d3.js 的工作示例吗?如果没有,我是否可以使用不同的 .json
所以,这就是它需要的样子 你在中心看到漂亮的白色效果,我试图重新创建它,但没有成功,这是我的代码: article .txt:after{ position:absolute; c
我在 中添加了一个框阴影并添加了一个 元素到 div。框阴影显示在 div 上,但它不会影响视频元素。 这是预期的行为吗,有没有办法让方框阴影也影响视频? 代码片段: .video-player {
设置: 我正在 Xcode 5 中处理一个显示一组文本字段的 View 。为了在键盘出现时处理滚动,我使用 ScrollView 来放置我的 TextFields。我使用自动布局。 问题: 我正在努力
我有 Auto Complete Mode为 Emacs 安装。 首先:当我输入声明时,我会得到正常的自动完成行为: 所以我点击了 Tab 来完成——没问题。但后来我点击了 ;: 它会立即尝试完成某些
如您所见,我想将搜索栏恰好放在 safeArea 的顶部,但是 proxy.safeAreaInsets 没有正确的值,因为在PreviewProvider 父级使用 edgesIgnoringSaf
将应用沙盒化后,如何使用“从登录时开始”功能制作应用? 最佳答案 谢谢CORY BOHON,他创建了以下教程: http://martiancraft.com/blog/2015/01/login-i
我是一名优秀的程序员,十分优秀!