UICollectionView
에서 장치를 회전 할 때 맞춤 레이아웃 (하위 클래스 : UICollectionViewLayout
)을 사용하여 신비한 동작을보고 있습니다.사용자 정의 레이아웃을 사용하는 UICollectionView 인터페이스 회전
저는 가로로 스크롤되는 셀 행을 가지고 있습니다. 장치를 세로에서 가로로 회전시킬 때 이전에 표시되지 않은 추가 셀이 표시되고 해당 셀의 애니메이션이 잘못되었습니다 (콜렉션보기의 기본 애니메이션 효과 인 익숙한 고스트 효과를 사용함). 레이아웃). 셀이 지금까지이 애니메이션에서 왼쪽에 나타나는주의 사항 : 사용자 정의 레이아웃 설정에 대한
일부 세부 정보 :
shouldInvalidateLayoutForBoundsChange:
반환YES
.- 에서
layoutAttributesForItemAtIndexPath:
은 아직 작성되지 않은 사전의 속성을 캐시합니다. layoutAttributesForElementsInRect:
에서 어떤 셀을 손으로 볼 수 있는지 계산하고 속성을 반환하기 전에 매번 약간의centre
속성을 조정하십시오.
나는 그 속성 최초/최종 레이아웃을 처리하기 위해 다음과 같은 코드를 가지고 : (어떻게 든하지 못했습니다 있습니다
- (void)prepareForAnimatedBoundsChange:(CGRect)oldBounds
{
[super prepareForAnimatedBoundsChange:oldBounds];
self.animatingBoundsChange = YES;
}
- (void)finalizeAnimatedBoundsChange
{
[super finalizeAnimatedBoundsChange];
self.animatingBoundsChange = NO;
}
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
if (self.animatingBoundsChange) {
// If the view is rotating, appearing items should animate from their current attributes (specify `nil`).
// Both of these appear to do much the same thing:
//return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
return nil;
}
return [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];
}
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
if (self.animatingBoundsChange) {
// If the view is rotating, disappearing items should animate to their new attributes.
return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
}
return [super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];
}
초기 레이아웃이 새롭게 나타나는 셀의 특성을 나에게 보인다 그것은 결국 올바른 위치에서으로 끝납니다). 그러나 initalLayout...
메서드에서 반환 된 레이아웃 속성의 center
속성을 기록 할 때 모든 것이 올바르게 보입니다. 가로 축을 따라 균등하게 간격을두고 있습니다.
initialLayout...
메서드가 호출 될 때 올바르게 애니메이션이 적용되지 않는 셀의 유일한 특징은 해당 셀이 [collectionView visibleCells]
배열로 반환되지 않는다는 것입니다. 그 앞에 오는 layoutAttributesForElementsInRect:
은 레이아웃 속성이 필요하다는 것을 정확하게 식별합니다.
무슨 일 이니? 후드 아래에서 진행되는 작업에 대한 통찰력이 도움이 될 것입니다 ... UICollectionView
은 거대한 블랙 박스처럼 보입니다.
http://stackoverflow.com/questions/12649271/what-is-the-best-best-way-to-disable-cross-fades- on-uicollectionview-uicollectio? rq = 1 –
iOS가 전환이 원활하게 이루어지지 않을 경우, 즉이 시나리오에서는 기존 셀과 충돌하는 모든 셀에서 크로스 페이드 애니메이션을 사용합니다. 이것은 iOS7의 UICollectionViews에있는 WWDC 비디오에 설명되어 있습니다. – Tim
@Arun_k 그 질문은이 질문과 관련이없는 것으로 보입니다. 그들은 왜 'initial/finalLayout ...'에 대한 설명을 요구하고 있습니다.'는 회전 할 때 호출되며 사실상 위의 코드를 추가하면 크로스 페이드 애니메이션이 방지됩니다. 이 질문은 움직이는 바운드가 변경된 후에 표시되는 추가 셀을 고려합니다. – Stuart