gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:03 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com