【发布时间】:2014-04-27 16:23:21
【问题描述】:
我有一个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];
}
}
}
【问题讨论】:
-
请发布您目前尝试过的代码
标签: ios objective-c uitableview transparent alpha