Я взял указанный ниже веб-сайт в качестве ссылки и попытался преобразовать его в код Swift. Обратитесь к разделу «collectioViewLayout», мне сложно привести все в порядок.
Я признателен. UICollectionVIew circleLayout
Исходный код выглядит следующим образом: -
- (CGSize)sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if ([[self.collectionView.delegate class] conformsToProtocol:@protocol(UICollectionViewDelegateFlowLayout)]) {
return [(id)self.collectionView.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath];
}
return CGSizeMake(0, 0);}
Мой исправленный быстрый код выглядит следующим образом: -
func sizeForItem(at indexPath: IndexPath?) -> CGSize {
if type(of: collectionView.delegate) is UICollectionViewDelegateFlowLayout {
if let indexPath = indexPath {
return collectionView!.delegate?.collectionView!(collectionView!, layout: self, sizeForItemAt: indexPath) ?? CGSize.zero
}
return CGSize.zero
}
return CGSize(width: 0, height: 0)
}
Однако некоторые ошибки возникли. (см. ниже)
Часть 1) Приведение из 'UICollectionViewDelegate? .Type' к несвязанному типу 'UICollectionViewDelegateFlowLayout' всегда терпит неудачу
Часть 2) Неверные метки аргументов в вызове (есть ': layout: sizeForItemAt:', ожидалось ': targetIndexPathForMoveFromItemAt: toProposedIndexPath:')
Есть ли кто-нибудь, кто может помочь мне исправить эту проблему быстрый код, пожалуйста?