Подкласс UICollectionViewFlowLayout
и переопределите метод layoutAttributesForElementsInRect:
, чтобы выровнять UICollectionViewCells
:
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray* array = [super layoutAttributesForElementsInRect:rect];
CGRect visibleRect;
visibleRect.origin = self.collectionView.contentOffset;
visibleRect.size = self.collectionView.bounds.size;
for(UICollectionViewLayoutAttributes* attributes in array) {
if(CGRectIntersectsRect(attributes.frame, rect)){
CGFloat d = UIInterfaceOrientationIsPortrait(_orientation)?
CGRectGetMidY(visibleRect)-attributes.center.y :
CGRectGetMidX(visibleRect)-attributes.center.x;
CGFloat w = visibleRect.size.width;
CGFloat h = visibleRect.size.height;
CGFloat dRatio = UIInterfaceOrientationIsPortrait(_orientation)? d/(h/2) : d/(w/2);
CGFloat angle = MAX_ANGLE*dRatio; // an angle between 0 and MAX_ANGLE based on proximity to center
CGFloat radians = DEGREES_TO_RADIANS(angle);
debug = 0;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = PERSPECTIVE;
rotationAndPerspectiveTransform = UIInterfaceOrientationIsPortrait(_orientation)?
CATransform3DRotate(rotationAndPerspectiveTransform, radians, 1.0f, 0.0f, 0.0f) :
CATransform3DRotate(rotationAndPerspectiveTransform, radians, 0.0f, 1.0f, 0.0f);
attributes.transform3D = rotationAndPerspectiveTransform;
}
}
return array;
}
Я не редактировал этот код для вас, и в нем есть ссылки на макросы и переменные экземпляра, поэтому вам нужно будет настроить его, чтобы он делал то, что вы хотите. Это использовалось для создания макета в стиле обложки, но принципы будут для вас теми же, но без 3D-бизнеса. Вам нужно установить вставку раздела, чтобы гарантировать одну строку или столбец в вашем потоке.
person
Lee Probert
schedule
12.03.2013