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

UITableView 的淡入淡出邊緣

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

問題描述

我對(duì)我的問題進(jìn)行了一些研究,不幸的是,我的問題沒有解決方案.最接近的是 在 UIImageView 接近邊緣時(shí)淡出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.

我希望我的表格在頂部應(yīng)用隱形漸變".如果單元格距離上邊緣 50 像素,它就會(huì)開始消失.越靠近上邊緣,零件越不可見.單元格高度約為 200 像素,因此單元格的下部需要 100% 可見.但沒關(guān)系 - 我需要一個(gè)表格視圖(或表格視圖容器)來執(zhí)行此任務(wù),因?yàn)轭愃频谋砀窨梢燥@示其他單元格.

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.

如果表格是純色視圖的子視圖,我可以通過添加一個(gè)水平漸變的圖像來實(shí)現(xiàn),我可以拉伸到任何寬度.該圖像的頂部像素以背景的確切顏色開始,向下相同顏色具有較少的 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.

但是……我們有一個(gè) 透明顏色 的 UITableView.表格下方?jīng)]有純色,而是圖案圖像/紋理,在應(yīng)用的其他屏幕上也可能不同.

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.

你有什么想法我可以實(shí)現(xiàn)這種行為嗎?

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

問候

推薦答案

我拿了本教程并進(jìn)行了一些更改和補(bǔ)充:

I took this tutorial and made some changes and additions:

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

1.首先導(dǎo)入 QuartzCore 并在控制器中設(shè)置遮罩層:

不需要在類中引用CAGradientLayer.

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

@interface mViewController : UIViewController
.
.
@end

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

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 中實(shí)現(xiàn) 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 椰子化學(xué)教程.

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

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

相關(guān)文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動(dòng)布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點(diǎn)擊手勢(shì)獲取索引或標(biāo)簽值)
UIScrollView not scrolling regardless of large contentSize(無論內(nèi)容大小如何,UIScrollView 都不會(huì)滾動(dòng))
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動(dòng)旋轉(zhuǎn)轉(zhuǎn)換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動(dòng)布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創(chuàng)建圖像)
主站蜘蛛池模板: 日韩乱码一二三 | 欧美理伦片在线播放 | 老司机精品福利视频 | 一区二区三区在线播放视频 | 日本在线视频中文字幕 | 国产欧美在线观看 | 欧美午夜一区 | 91精品国产色综合久久不卡98口 | 射久久 | 免费看片国产 | 亚洲91视频 | 青青草在线视频免费观看 | 操夜夜| 人妖av| 日韩欧美大片在线观看 | 欧美黄色片在线观看 | 中文天堂在线观看 | 精品视频在线观看 | 久久91精品国产一区二区 | 亚洲福利一区二区 | 国产一区二 | 久产久精国产品 | 精品免费视频一区二区 | 一区二区三区欧美大片 | 一二区视频 | 国产日韩在线观看一区 | 国产午夜精品一区二区三区在线观看 | 欧美日韩在线不卡 | 黄网免费看 | 国产欧美精品一区二区三区 | 日韩一区二区三区在线视频 | 精品国产乱码久久久久久影片 | 亚洲视频一区在线观看 | 国产精品不卡视频 | 粉嫩粉嫩芽的虎白女18在线视频 | 日韩有码一区 | 久久久中文 | 日本国产一区二区 | 成人国产在线视频 | 日本人爽p大片免费看 | 久久久久久国产 |