我有 UICollectionView 和流布局,其中估计大小设置为automaticSize。
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
我在单元格中有 UITextView 输入,我的目标是拥有自动调整大小的单元格。因此,在单元格输入中的每个文本更改中,我都会使布局中更改的单元格与上下文无效。
let context = UICollectionViewFlowLayoutInvalidationContext()
context.invalidateFlowLayoutAttributes = false
context.invalidateItems(at: [indexPath])
collectionView.collectionViewLayout.invalidateLayout(with: context)
Run Code Online (Sandbox Code Playgroud)
为了获得正确的单元格高度,我覆盖preferredLayoutAttributesFitting单元格并动态计算高度。它在 iOS 12 上运行得很好,collectionView.collectionViewLayout.invalidateLayout(with: context)强制preferredLayoutAttributesFitting调用。但在 iOS 13 上,除非我滚动集合视图,否则不会调用它。
我找不到 iOS 13 中的任何更改UICollectionViewFlowLayoutInvalidationContext,有什么想法吗?
我知道关于这个主题有很多(在 Xamarin.Forms ScrollView 中水平滚动),但我无法实现水平滚动的水平滚动视图。
public class DetailView : ContentPage
{
public DetailView ()
{
StackLayout stack = new StackLayout {
Orientation = StackOrientation.Horizontal,
};
for (int i = 0; i < 40; i++)
stack.Children.Add (new Button { Text = "Button" });
var scrollView = new ScrollView
{
Orientation = ScrollOrientation.Horizontal,
Content = stack
};
Content = scrollView;
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我在使用ObjectMapper将json映射到我的对象数组时遇到了麻烦.这是我的模型对象.
class Participant : Mappable {
var user_global_id: String!
var user_app_id: String!
init(){
}
required init?(_ map: Map) {
}
// Mappable
func mapping(map: Map) {
user_global_id <- map["user_global_id"]
user_app_id <- map["user_app_id"]
}
}
Run Code Online (Sandbox Code Playgroud)
而我的json看起来: "[{\"user_global_id\":5093363330056192,\"user_app_id\":11}]"
我在调用ObjectMapper:
let participants = Mapper<[Participant]>().map(json["registeredParticipants"])
Run Code Online (Sandbox Code Playgroud)
上面的行给出错误: Type '[Participant]' does not conform to protocol 'Mappable'