久久久久久久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 創建圖像)
主站蜘蛛池模板: av网站免费在线观看 | 国产成人精品免费 | 日韩亚洲视频在线 | 美女张开腿露出尿口 | 伊人网站在线观看 | 国产一级片精品 | 国产精品久久久久久中文字 | 成人精品视频在线观看 | 欧美在线视频网 | av中文字幕在线播放 | 国产精品久久久久aaaa九色 | 污书屋| av网站在线播放 | 国产午夜精品久久久久 | 一区二区中文 | 中文字幕一区二区三区不卡在线 | 欧美精品在线一区二区三区 | 麻豆天堂 | 网址黄 | 国产精品视频久久 | 精品综合 | sese视频在线观看 | 蜜桃精品视频在线 | 午夜精品久久久久久久久久久久 | 欧美日韩一区二区三区视频 | 日韩欧美一区二区三区免费观看 | 日本亚洲一区 | 欧美v日韩v | 国产99精品 | 欧美激情综合五月色丁香小说 | 伊人网站在线观看 | av在线成人 | 欧美日韩在线观看一区二区三区 | 亚洲福利网 | 一区二区在线免费播放 | 日一区二区| 国产亚洲成av人在线观看导航 | 国产一区精品在线 | 精品毛片在线观看 | 亚洲影音先锋 | 国产精品亚洲精品日韩已方 |