Swift 3 CollectionView缩放(Swift 3 CollectionView scaling)
我最近在应用程序中实现了一个集合视图,我遇到的唯一问题是集合视图在较小的设备上从2列到1列,两侧有很多填充
我确实尝试了几种方法,如果显示宽度小于一定数量,它会扩大细胞,但它无法解决,因为细胞确实按比例放大但没有居中和重叠自身。
I recently implemented a collection view in a app, the only problem I'm experiencing is that the collection view goes from 2 column to 1 column on smaller devices with a lot of padding on both sides
heres on a display smaller then a iPhone 6:
and heres how it looks on a display bigger or equal to a iPhone 6:
I did try several method where if the display width was smaller then a certain number it would scale up the cells, but it failed to work out because the cells where indeed scaled up but where not centered and over-lapping themselves.
原文:https://stackoverflow.com/questions/40822239
最满意答案
尝试这个
a = [1,2,3,4,5,6,7,8,9,10] slices = [1,2,3,4].map { |n| a.shift(n) }
这将数组分片
注意,这会改变原始数组。
Try this
a = [1,2,3,4,5,6,7,8,9,10] slices = [1,2,3,4].map { |n| a.shift(n) }
This slices the array into pieces
NB, this mutates the original array.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
像大多数迭代器方法一样, each_slice返回一个可枚举的,当没有一个块的时候调用ruby 1.8.7+,然后可以调用其他可枚举的方法。 所以你可以做: arr.each_slice(2).with_index { |(a, b), i| puts "#{i} - #{a}, #{b}" } Like most iterator methods, each_slice returns an enumerable when called without a block since ruby 1.8.7+ ...
-
如何在bash中切割数组(How to slice an array in Bash)[2021-10-20]
请参阅Bash man页中的“ 参数扩展”部分。 A[@]返回数组的内容:1:2采用长度为2的片段,从索引1开始。 A=( foo bar "a b c" 42 ) B=("${A[@]:1:2}") C=("${A[@]:1}") # slice to the end of the array echo "${B[@]}" # bar a b c echo "${B[1]}" # a b c echo "${C[@]}" # bar a b c 42 注意,“abc”是一个 ... -
array = ["A", "B", "C", "D"] array => ["A", "B", "C", "D"] array.each_slice(2).to_a => [["A", "B"], ["C", "D"]] array.each_slice(2).to_a.length => 2 也许你期待array.each_slice(2).to_a会改变你的原始array ,但是在这里你将拥有新的Array对象,因为each_slice是非破坏性的方法,就像Ruby中的大部分一样。 ne ...
-
将数组切片成数组(Slice Array into an array of arrays)[2023-07-05]
使用常规while循环和自定义step参数的解决方案: function sliceArrayIntoGroups(arr, size) { var step = 0, sliceArr = [], len = arr.length; while (step < len) { sliceArr.push(arr.slice(step, step += size)); } return sliceArr; } console.log(sliceArrayIntoGro ... -
l = my_2D_array.map(&:length).max my_2D_array.each{|e| e[l - 1] ||= nil} l = my_2D_array.map(&:length).max my_2D_array.each{|e| e[l - 1] ||= nil}
-
你可以做: index = 4 length = 3 [ "a", "b", "c", "d", "e" ].cycle.take(index + length).last(length) You can do: index = 4 length = 3 [ "a", "b", "c", "d", "e" ].cycle.take(index + length).last(length)
-
如何在Ruby 1.9中使用带有initial_state的“slice_before”?(How do I use “slice_before” with initial_state in Ruby 1.9?)[2021-10-05]
initial_state通常是存储键值对的状态哈希。 要使用状态哈希编写代码: a.slice_before(sum: 0) do |elem, state| state[:sum] += elem if state[:sum] > 3 # Reset the sum, so we'll get more elements state[:sum] = 0 end end.to_a initial_state必须响应#dup方法,因为它在每个循环中都是重复的。 Fixnum ... -
如何将ruby中的数组切割为指定长度的子数组?(How do I slice an array in ruby into sub arrays of a specified length?)[2023-06-22]
尝试这个 a = [1,2,3,4,5,6,7,8,9,10] slices = [1,2,3,4].map { |n| a.shift(n) } 这将数组分片 注意,这会改变原始数组。 Try this a = [1,2,3,4,5,6,7,8,9,10] slices = [1,2,3,4].map { |n| a.shift(n) } This slices the array into pieces NB, this mutates the original array. -
each_slice生成最大所需大小的切片; 它不会直接在这里完成你想要的东西,这是一种“平衡”的清单。 幸运的是,我们可以到达那里。 list = (1..10).to_a slice_count = (list.length / 3.0).floor list.each_slice(slice_count).to_a.each {|l| l.fill nil, slice_count, 0 }.transpose.map(&:compact) # => [[1, 4, 7, 10], [2, 5, 8] ...