JBParallaxCell 0.0.1

JBParallaxCell 0.0.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014 年 12 月

Javier Berlana 维护。



iOS 在 UITableViewCell 的图像上实现视差效果

此项目的目标是当表格滚动时,在 UITableViewCell 上的 UIImageView 上创建视差效果。

此代码最初是为了在 meets 的发现标签上提供视差效果而创建的。

image

下载应用程序并免费试用!欢迎反馈!下载应用程序

文档

在您的 UITableViewCell

  1. parallaxImageView 放入具有 clipsToBounds = YES;UIView 中,并设置一些偏移量。
  2. 添加此函数以计算在 UITableView 滚动时的图像偏移量。
- (void)cellOnTableView:(UITableView *)tableView didScrollOnView:(UIView *)view
{
    CGRect rectInSuperview = [tableView convertRect:self.frame toView:view];

    float distanceFromCenter = CGRectGetHeight(view.frame)/2 - CGRectGetMinY(rectInSuperview);
    float difference = CGRectGetHeight(self.parallaxImage.frame) - CGRectGetHeight(self.frame);
    float move = (distanceFromCenter / CGRectGetHeight(view.frame)) * difference;

    CGRect imageRect = self.parallaxImage.frame;
    imageRect.origin.y = -(difference/2)+move;
    self.parallaxImage.frame = imageRect;
}

在您的 UITableViewDelegate 中添加此函数。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // Get visible cells on table view.
    NSArray *visibleCells = [self.tableView visibleCells];

    for (JBParallaxCell *cell in visibleCells) {
        [cell cellOnTableView:self.tableView didScrollOnView:self.view];
    }
}

就是这样,您可以通过演示项目来查看一切是如何协同工作的。

meets,与您的朋友共同创建和探索计划。