我有一个 UITableViewController
,其中包含一个用于我的 UITableViewCell
的自定义类。我在这个 UITableViewCell
上有一个 UIImageView
和一个 UILabel
。
我希望 UITableViewCell
上的内容在屏幕上的某个 y 值以上时变得更加半透明/透明,这样你会得到一个“淡入淡出的效果”,类似于 Rdio应用:
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/