Koleksiyonumda yaklaşık 14 öğe var Görünüş ve kaydırma işlemi hiç düzgün değil. Otomatik düzen kullanıyorum (kısıtlarım günlükleri kaydetmez) ve ben cornerRadius özelliğini kullanıyorum (bu bir mesajlaşma uygulamasıdır).UICollectionView Scroll Performance Horrible
Ben Zaman Profiler cihazı kullanarak analiz denedim ve bu ı kaydırırken gördükleri oldu:
Maalesef gri olur "Xcode Göstermektedir", bu yüzden yapamam Tam olarak hangi çizginin sonsuza kadar sürdüğünü görün. Her bir öğenin büyüklüğünü hesaplıyorum. Ne kadar büyük 9377 ms gecikme olabileceğini merak ediyorum? Doğru hatırlarsam, sipariş setlerini kullanmıyorum.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//Retrieve the right message
Message *message = (Message *)[self.messages objectAtIndex:indexPath.row];
//Check Message Type
switch (message.type) {
case MessageTypeText: {
//Create a temporary cell to get the correct size
TextMessageItem *tempCell = [[TextMessageItem alloc] init];
//Configure the cell
[self collectionView:collectionView configureTextCell:tempCell atIndexPath:indexPath];
CGSize s = [tempCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize withHorizontalFittingPriority:UILayoutPriorityDefaultHigh verticalFittingPriority:UILayoutPriorityDefaultLow];
//Return Content Size
return CGSizeMake(self.collectionView.bounds.size.width, s.height);
break;
}
}
//Return
return CGSizeMake(0, 0);
}
Benim WillDisplayCell
Yöntem:
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
//Retrieve message from our array of messages
Message *message = (Message *)[self.messages objectAtIndex:indexPath.row];
//Check Message Type
switch (message.type) {
case MessageTypeText: {
//Cast Cell
TextMessageItem *textItem = (TextMessageItem *)cell;
[self collectionView:collectionView configureTextCell:textItem atIndexPath:indexPath];
break;
}
}
}
Ve son olarak, bu benim gelenektir
İşte- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//Define Message
Message *message = (Message *)[self.messages objectAtIndex:indexPath.item];
//Check Message Type
switch (message.type) {
case MessageTypeText: {
//Initialize Cell
TextMessageItem *cell = (TextMessageItem *)[collectionView dequeueReusableCellWithReuseIdentifier:kTextMessageItemIdentifier forIndexPath:indexPath];
//Return Cell
return cell;
break;
}
}
return nil;
}
i yüksekliğini hesap yapıyorum edebilirsiniz:
İşte benim cellForItemAtIndexpath
yöntemidir configureTextCell
yöntem:
- (void)collectionView:(UICollectionView *)collectionView configureTextCell:(TextMessageItem *)item atIndexPath:(NSIndexPath *)indexPath {
//Retrieve Message
Message *message = (Message *)[self.messages objectAtIndex:indexPath.item];
//Display Timestamp if Needed
[self displayTimestampForItemIfNeeded:item atIndex:indexPath.item];
//Update Top Message Padding Based On Who Sent The Previous Message
[self updateDistanceFromPreviousMessageForItem:item atIndex:indexPath.item];
//Display Delivery Status if Needed (e.g. Delivered)
[self displayDeliveryStatusForItemIfNeeded:item atIndex:indexPath.item];
//Set Message
[item setMessage:message];
}
"cellForItemAtIndexpath" cihazım doğru şekilde uygulanmamış olabilir mi? 'UICollectionViewCell' alt sınıfım program aracılığıyla yapılır (storyboard veya xib dosyası yok) ve başlangıçtaki yükte,' initWithFrame' yönteminin self.messages dizimdeki her öğe için çağrıldığını fark ettim. Bu normal mi? – KingPolygon