2016-11-28 1 views
2

Je veux mettre en œuvre une animation comme insorts et feed-news app faire. J'ai trouvé la version rapide il est réalisé par la personnalisation de la disposition uicollectionview.Comment mettre en œuvre l'animation comme Feedly, insère l'application de nouvelles dans iOS objectif-c

Voici le lien

Depth Page transform on iOS je convertir rapidement à c objective mais pas atteint même effet.

Voici mon code

importation "DepthLayout.h"

@interface DepthLayout() { 
    CGFloat contentWidth; 
    CGFloat contentHeight; 
    CGFloat yOffset; 
    CGFloat maxAlpha; 
    CGFloat minAlpha; 
    CGFloat widthOffset; 
    CGFloat heightOffset; 
    NSMutableArray * cache; 
} 
@end 

@implementation DepthLayout 
#pragma mark - Lifecycle 

- (id)init 
{ 
    self = [super init]; 
    if (self) { 
     [self setup]; 
    } 

    return self; 
} 

- (id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super init]; 
    if (self) { 
     [self setup]; 
    } 

    return self; 
} 

- (void)setup 
{ 

    yOffset=0; 
    maxAlpha=1; 
    minAlpha=0; 
    widthOffset=35; 
    heightOffset=35; 
    cache=[[NSMutableArray alloc]init]; 

} 
-(CGFloat)itemWidth{ 
    return CGRectGetWidth(self.collectionView.bounds); 

} 
-(CGFloat)itemHeight{ 
    return CGRectGetHeight(self.collectionView.bounds); 

} 
-(CGFloat)collectionViewHeight{ 
    return CGRectGetHeight(self.collectionView.bounds); 

} 
-(NSInteger)numberOfItems{ 
    return [self.collectionView numberOfItemsInSection:0]; 

} 
-(CGFloat)dragOffset{ 
    return CGRectGetHeight(self.collectionView.bounds); 

} 
-(NSInteger)currentItemIndex{ 
    return MAX(0,(NSInteger)(self.collectionView.contentOffset.y/[self collectionViewHeight])); 

} 
-(CGFloat)nextItemBecomeCurrentPercentage{ 
    return (self.collectionView.contentOffset.y/[self collectionViewHeight])-(CGFloat)[self currentItemIndex]; 

} 
#pragma mark - Layout 

- (void)prepareLayout{ 
    [cache removeAllObjects]; 
    yOffset=0; 
    for(NSInteger item=0;item<[self numberOfItems];item++){ 
     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; 
     UICollectionViewLayoutAttributes *attribute = 
     [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 
     if ((indexPath.item == [self currentItemIndex ]+1) && (indexPath.item < [self numberOfItems])){ 
      attribute.alpha = minAlpha + MAX((maxAlpha-minAlpha) * [self nextItemBecomeCurrentPercentage], 0); 
      CGFloat width = [self itemWidth] - widthOffset + (widthOffset * [self nextItemBecomeCurrentPercentage]); 
      CGFloat height = [self itemWidth] - heightOffset + (heightOffset * [self nextItemBecomeCurrentPercentage]); 
      CGFloat deltaWidth = width/[self itemWidth]; 
      CGFloat deltaHeight = height/[self itemHeight ]; 
      attribute.frame = CGRectMake(0, yOffset, [self itemWidth],[self itemHeight]); 
      attribute.transform = CGAffineTransformMakeScale(deltaWidth, deltaHeight); 
      CGPoint center=self.collectionView.center; 
      center.y=self.collectionView.center.y+self.collectionView.contentOffset.y; 
      center.x=self.collectionView.center.x+self.collectionView.contentOffset.x; 
      attribute.center = center; 
      yOffset += [self collectionViewHeight]; 

     }else{ 
      attribute.frame = CGRectMake(0, yOffset, [self itemWidth],[self itemHeight]); 
      CGPoint center=self.collectionView.center; 
      center.y=self.collectionView.center.y+yOffset; 
      center.x=self.collectionView.center.x; 
      yOffset += [self collectionViewHeight]; 
     } 
     [cache addObject:attribute]; 
    } 

} 

-(CGSize)collectionViewContentSize{ 
    contentWidth = CGRectGetWidth(self.collectionView.bounds); 
    contentHeight = (CGFloat)[self numberOfItems] * CGRectGetHeight(self.collectionView.bounds); 
    return CGSizeMake(contentWidth, contentHeight); 
} 
-(NSMutableArray *)layoutAttributesForElementsInRect:(CGRect)rect{ 


    NSMutableArray* layoutAttributes = [[NSMutableArray alloc]init]; 
    for (UICollectionViewLayoutAttributes * attribute in cache){ 
     if(CGRectIntersectsRect(attribute.frame, rect)){ 
      [layoutAttributes addObject:attribute]; 
     } 
    } 
    return layoutAttributes; 
} 
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{ 
    return YES; 
} 
-(CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity{ 
    NSInteger itemIndex = round(proposedContentOffset.y/([self dragOffset])); 
    CGFloat yOffsetTemp = itemIndex * CGRectGetHeight(self.collectionView.bounds); 
    return CGPointMake(0, yOffsetTemp); 

} 
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath*)indexPath { 

    UICollectionViewLayoutAttributes *attr=[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 
    return attr; 
} 
@end 

Quel est le problème?

Répondre

0

Pas besoin de convertir swift en objectif c.

I Utilisez le fichier Swift directement dans mon projet Objective C qui répond à mes exigences.

Je UltravisualLayout utilisé à partir d'ici: Depth Page transform on iOS

Merci Bridging entre l'objectif rapide & C;