ios - 获取每个 UITableViewCell 在屏幕上的当前 y 值位置

标签 ios objective-c uitableview transparent alpha

我有一个 UITableViewController,其中包含一个用于我的 UITableViewCell 的自定义类。我在这个 UITableViewCell 上有一个 UIImageView 和一个 UILabel

我希望 UITableViewCell 上的内容在屏幕上的某个 y 值以上时变得更加半透明/透明,这样你会得到一个“淡入淡出的效果”,类似于 Rdio应用:

The alpha value of the <code>UIImageView</code> and UILabel are 1.0 Now the value is lower, like 0.7 or something.

MyUIViewController.h

@property (strong, nonatomic) IBOutlet UITableView *tableview;

MyUIViewController.m

@synthesize tableview;

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

    NSArray *listOfVisibleCells = tableview.visibleCells;

    for (int i=0; i<[listOfVisibleCells count]; i++) {

        MTTableViewCell *cell = [listOfVisibleCells objectAtIndex:i];

        /* Smooth fade out */
        if (scrollView.contentOffset.y > (cell.frame.origin.y + 10)) {
            [cell.companyImage setAlpha:0.7];
        }
        if (scrollView.contentOffset.y > (cell.frame.origin.y + 20)) {
            [cell.companyImage setAlpha:0.5];
        }
        if (scrollView.contentOffset.y > (cell.frame.origin.y + 30)) {
            [cell.companyImage setAlpha:0.3];
        }
        if (scrollView.contentOffset.y > (cell.frame.origin.y + 40)) {
            [cell.companyImage setAlpha:0.1];
        }

        /* Fade in */
        if (scrollView.contentOffset.y < (cell.frame.origin.y + 10)) {
            [cell.companyImage setAlpha:1.0];
        }
    }
}

最佳答案

这一行:

if (scrollView.contentOffset.y > ((i*90)+30) ) {

应该是:

if (scrollView.contentOffset.y > (cell.frame.origin.y + 30)) {

关于ios - 获取每个 UITableViewCell 在屏幕上的当前 y 值位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23325835/

相关文章:

iphone - 如何以编程方式从 plist 添加和检索数据

iOS 应用程序在方法调用时崩溃

iphone - 关于数据驱动的 iPhone 应用程序的建议和技巧

ios - 如何在 applicationWillTerminate 方法中调用 Web 服务并停止 VPN 服务器?

ios - 使用Kiwi测试MagicalRecord对象时,默认上下文为nil

ios - 固定高度 subview 的自动布局约束警告

ios - UITableView 在从纵向旋转到横向,再回到纵向时会更改大小

ios - CATransform3D.MakeScale 正在移动层

ios - 从 TableView Objective C 获取 IndexPath.Row

ios - UISegmentedControl 在 UITableView 标题上的行为方式很奇怪