pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

UITableView 的淡入淡出邊緣

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

問題描述

我對我的問題進(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 像素,它就會開始消失.越靠近上邊緣,零件越不可見.單元格高度約為 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)容如何,??它都能正常工作.
  • 掩碼的變化取決于表格視圖的位置 - 滾動到頂部時(shí)只有底部褪色,滾動到底部時(shí)只有頂部褪色...

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

不需要在類中引用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 中實(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 的淡入淡出邊緣的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點(diǎn)擊手勢獲取索引或標(biāo)簽值)
UIScrollView not scrolling regardless of large contentSize(無論內(nèi)容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉(zhuǎn)轉(zhuǎn)換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創(chuàng)建圖像)
主站蜘蛛池模板: 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 隧道风机_DWEX边墙风机_SDS射流风机-绍兴市上虞科瑞风机有限公司 | 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 上海电子秤厂家,电子秤厂家价格,上海吊秤厂家,吊秤供应价格-上海佳宜电子科技有限公司 | 辽宁资质代办_辽宁建筑资质办理_辽宁建筑资质延期升级_辽宁中杭资质代办 | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 杭州顺源过滤机械有限公司官网-压滤机_板框压滤机_厢式隔膜压滤机厂家 | 周易算网-八字测算网 - 周易算网-宝宝起名取名测名字周易八字测算网 | 不锈钢/气体/液体玻璃转子流量计(防腐,选型,规格)-常州天晟热工仪表有限公司【官网】 | 代理记账_公司起名核名_公司注册_工商注册-睿婕实业有限公司 | 净化板-洁净板-净化板价格-净化板生产厂家-山东鸿星新材料科技股份有限公司 | 工控机-工业平板电脑-研华工控机-研越无风扇嵌入式box工控机 | 东莞画册设计_logo/vi设计_品牌包装设计 - 华略品牌设计公司 | 法兰螺母 - 不锈钢螺母制造厂家 - 万千紧固件--螺母街 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 螺旋压榨机-刮泥机-潜水搅拌机-电动泥斗-潜水推流器-南京格林兰环保设备有限公司 | 磁力抛光机_磁力研磨机_磁力去毛刺机-冠古设备厂家|维修|租赁【官网】 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 | 深圳宣传片制作-企业宣传视频制作-产品视频拍摄-产品动画制作-短视频拍摄制作公司 | 论文查重_免费论文查重_知网学术不端论文查重检测系统入口_论文查重软件 | 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 塑钢件_塑钢门窗配件_塑钢配件厂家-文安县启泰金属制品有限公司 深圳南财多媒体有限公司介绍 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 工控机-图像采集卡-PoE网卡-人工智能-工业主板-深圳朗锐智科 | 全自动实验室洗瓶机,移液管|培养皿|进样瓶清洗机,清洗剂-广州摩特伟希尔机械设备有限责任公司 | 背压阀|减压器|不锈钢减压器|减压阀|卫生级背压阀|单向阀|背压阀厂家-上海沃原自控阀门有限公司 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 【德信自动化】点胶机_全自动点胶机_自动点胶机厂家_塑料热压机_自动螺丝机-深圳市德信自动化设备有限公司 | 带式过滤机厂家_价格_型号规格参数-江西核威环保科技有限公司 | 西宁装修_西宁装修公司-西宁业之峰装饰-青海业之峰墅级装饰设计公司【官网】 | 二手注塑机回收_旧注塑机回收_二手注塑机买卖 - 大鑫二手注塑机 二手光谱仪维修-德国OBLF光谱仪|进口斯派克光谱仪-热电ARL光谱仪-意大利GNR光谱仪-永晖检测 | Win10系统下载_32位/64位系统/专业版/纯净版下载 | 特种电缆厂家-硅橡胶耐高温电缆-耐低温补偿导线-安徽万邦特种电缆有限公司 | 高博医疗集团上海阿特蒙医院 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 河南中专学校|职高|技校招生-河南中职中专网| 面粉仓_储酒罐_不锈钢储酒罐厂家-泰安鑫佳机械制造有限公司 | 棕刚玉-白刚玉厂家价格_巩义市东翔净水材料厂 | 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 芜湖厨房设备_芜湖商用厨具_芜湖厨具设备-芜湖鑫环厨具有限公司 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 |