久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UITableView 的淡入淡出邊緣

Fade edges of UITableView(UITableView 的淡入淡出邊緣)
本文介紹了UITableView 的淡入淡出邊緣的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我對我的問題進行了一些研究,不幸的是,我的問題沒有解決方案.最接近的是 在 UIImageView 接近邊緣時淡出UIScrollView 但它仍然不適合我.

I've made a little research about my problem and unfortunately there was no solution for my problem. The closest was Fade UIImageView as it approaches the edges of a UIScrollView but it's still not for me.

我希望我的表格在頂部應用隱形漸變".如果單元格距離上邊緣 50 像素,它就會開始消失.越靠近上邊緣,零件越不可見.單元格高度約為 200 像素,因此單元格的下部需要 100% 可見.但沒關系 - 我需要一個表格視圖(或表格視圖容器)來執行此任務,因為類似的表格可以顯示其他單元格.

I want my table to apply an "invisibility gradient" on the top. If the cell is at a 50px distance from the top edge it starts to vanish. The closer it is to the upper edge, the more invisible the part is. The cells height is about 200 pixels, so the lower part of the cell need to be visible in 100%. But nevermind - I need a table view (or table view container) to do this task, because similar tables can display other cells.

如果表格是純色視圖的子視圖,我可以通過添加一個水平漸變的圖像來實現,我可以拉伸到任何寬度.該圖像的頂部像素以背景的確切顏色開始,向下相同顏色具有較少的 alpha.

If the table is a subview of a solid color view, I can achieve that by adding an image which is a horizontal gradient that I can streach to any width. The top pixel of that image starts with the exact color of the background, and going down the same color has less alpha.

但是……我們有一個 透明顏色 的 UITableView.表格下方沒有純色,而是圖案圖像/紋理,在應用的其他屏幕上也可能不同.

But... we have a UITableView with transparent color. Below the table there is no solid color, but a pattern image/texture, that can also be different on other screens of the app.

你有什么想法我可以實現這種行為嗎?

Do you have any Idea how I can achieve this behaviour?

問候

推薦答案

我拿了本教程并進行了一些更改和補充:

I took this tutorial and made some changes and additions:

  • 它現在適用于所有表格視圖 - 即使它們是更大屏幕的一部分.
  • 無論背景或 tableview 后面的任何內容如何,??它都能正常工作.
  • 掩碼的變化取決于表格視圖的位置 - 滾動到頂部時只有底部褪色,滾動到底部時只有頂部褪色...

1.首先導入 QuartzCore 并在控制器中設置遮罩層:

不需要在類中引用CAGradientLayer.

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface mViewController : UIViewController
.
.
@end

2. 將此添加到 viewWillAppear viewDidLayoutSubviews:(查看@Darren 對此的評論)

2. Add this to viewWillAppear viewDidLayoutSubviews: (See @Darren's comment on this one)

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    if (!self.tableView.layer.mask)
    {
        CAGradientLayer *maskLayer = [CAGradientLayer layer];

        maskLayer.locations = @[[NSNumber numberWithFloat:0.0], 
                                [NSNumber numberWithFloat:0.2], 
                                [NSNumber numberWithFloat:0.8], 
                                [NSNumber numberWithFloat:1.0]];

        maskLayer.bounds = CGRectMake(0, 0,
                            self.tableView.frame.size.width,
                            self.tableView.frame.size.height);
        maskLayer.anchorPoint = CGPointZero;

       self.tableView.layer.mask = maskLayer;
    }
    [self scrollViewDidScroll:self.tableView];
}

3. 通過將 UIScrollViewDelegate 添加到控制器的 .h 中,確保您是代表:

3. Make sure you are a delegate of UIScrollViewDelegate by adding it in the .h of your controller:

@interface mViewController : UIViewController <UIScrollViewDelegate>

4. 最后,在控制器 .m 中實現 scrollViewDidScroll:

4. To finish, implement scrollViewDidScroll in your controller .m:

#pragma mark - Scroll View Delegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGColorRef outerColor = [UIColor colorWithWhite:1.0 alpha:0.0].CGColor;
    CGColorRef innerColor = [UIColor colorWithWhite:1.0 alpha:1.0].CGColor;
    NSArray *colors;

    if (scrollView.contentOffset.y + scrollView.contentInset.top <= 0) {
        //Top of scrollView
        colors = @[(__bridge id)innerColor, (__bridge id)innerColor,
                   (__bridge id)innerColor, (__bridge id)outerColor];
    } else if (scrollView.contentOffset.y + scrollView.frame.size.height
               >= scrollView.contentSize.height) {
        //Bottom of tableView
        colors = @[(__bridge id)outerColor, (__bridge id)innerColor,
                   (__bridge id)innerColor, (__bridge id)innerColor];
    } else {
        //Middle
        colors = @[(__bridge id)outerColor, (__bridge id)innerColor,
                   (__bridge id)innerColor, (__bridge id)outerColor];
    }
    ((CAGradientLayer *)scrollView.layer.mask).colors = colors;

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    scrollView.layer.mask.position = CGPointMake(0, scrollView.contentOffset.y);
    [CATransaction commit];
}

再次重申:大部分解決方案來自 this 椰子化學教程.

這篇關于UITableView 的淡入淡出邊緣的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 亚洲免费久久 | 国产中文字幕一区二区 | 日韩免费视频一区二区 | 男人天堂网址 | 久久精品国产一区 | 99热在线观看 | 日韩在线不卡 | 亚洲欧美日本在线 | 在线看黄色片 | 国产小视频在线 | 91av免费观看 | 哦┅┅快┅┅用力啊┅aps | 人人看人人草 | 夜夜骑夜夜操 | 亚洲久久久久久 | 欧美日韩一区二 | 国产成人免费在线观看 | 美国特色黄a大片 | 亚洲一区二区三区在线视频 | 国产成人免费观看 | 亚洲视频中文字幕 | 亚洲国产一区在线 | 成人一区二区在线 | 成人欧美一区二区三区白人 | 午夜专区 | 久久久久婷婷 | 人人干人人艹 | 国产在线资源 | 日韩免费观看视频 | 午夜在线观看视频网站 | 中文在线免费观看 | 日韩成人中文字幕 | 日本一级淫片 | 午夜性影院 | 精品久久影院 | 中文字幕第2页 | a在线视频| 成人免费黄色大片 | 国产精品日韩欧美 | 欧美视频在线观看 | 中文字幕在线观看免费视频 |