列出像Fleck iOS应用程序

时间:2014-07-23 22:14:45

标签: ios list scroll

我想创建一个像Fleck app(https://itunes.apple.com/us/app/fleck-the-bigger-picture/id619977675)这样的滚动视图。滚动项目时,请更改其高度。一个增加其他减少

我创造了这个。但这项工作很奇怪。也许有类似的元素。他们可以帮助我...

@interface FleckView()

@property (strong, nonatomic) NSMutableArray* items;
@property (strong, nonatomic) NSMutableArray* cells;

@property (assign, nonatomic) CGFloat old_y;
@property (assign, nonatomic) CGFloat step;

@end

@implementation FleckView


#define kCellHeight 80.0
#define kCellHeightActive 320.0
int counter = 0;
float diff = (kCellHeightActive - kCellHeight) / kCellHeight; // 3.5


- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
return self;
}

-(void) loadItems: (NSMutableArray*) items{

self.old_y = 0;
self.step = 0;

self.delegate = self;
self.cells = [[NSMutableArray alloc] init];

self.items = items;

self.contentSize = CGSizeMake(320, kCellHeightActive + (self.items.count) * kCellHeight);


//add first
UIView *view = [self.items objectAtIndex:0];

view.frame = CGRectMake(0, 0, 320, kCellHeightActive);

[self.cells addObject: view];

[self addSubview:view];


//add other
for(int i = 1; i < self.items.count; i++){

    UIView *view = [self.items objectAtIndex:i];

    view.frame = CGRectMake(0, ((i - 1) * kCellHeight) + kCellHeightActive, 320, kCellHeight);

    [self.cells addObject: view];

    [self addSubview:view];
}
}



////MAIN WORK


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{

counter = (scrollView.contentOffset.y) / kCellHeight ;

self.step = scrollView.contentOffset.y - self.old_y;
self.old_y = scrollView.contentOffset.y;

if(counter < self.items.count){

    [self setHeightRow: counter + 1];



}





}



-(void) setHeightRow: (int) rowNum{

UIView *cell_prev = [self.cells objectAtIndex: rowNum - 1];
UIView *cell = [self.cells objectAtIndex: rowNum];

CGFloat height = cell.frame.size.height;
height = height + (self.step * diff);

if(height < 90)
    height = 80;

CGFloat height_prev = kCellHeightActive + kCellHeight - height;

NSLog(@"HEIGHT_PREV: %f", height_prev);
NSLog(@"HEIGHT: %f", height);

CGFloat y_prev = counter * kCellHeight;
CGFloat y = y_prev + height_prev;

NSLog(@"___Y_PREV: %f", y_prev);
NSLog(@"___Y: %f", y);

cell_prev.frame = CGRectMake(0, y_prev, 320, height_prev);
cell.frame = CGRectMake(0, y, 320, height);

}



- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity       targetContentOffset:(inout CGPoint *)targetContentOffset {

float bottom = counter * kCellHeight;
float top = (counter + 1) * kCellHeight;

if(targetContentOffset->y > kCellHeight / 2 + counter * kCellHeight){


    targetContentOffset->y = top;
}
else{

    targetContentOffset->y = bottom;
}



}

0 个答案:

没有答案