V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
xhacker
V2EX  ›  iDev

iOS 上如何实现排除某个 view 的 mask 效果?

  •  
  •   xhacker ·
    xhacker · 2014-01-31 15:23:10 +08:00 · 4378 次点击
    这是一个创建于 3744 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大概就是 Clear 那样,点击一个 row 之后其他部分都变暗,除了这个 row 还是亮的。

    现有一个 table view,我也想实现点击一个 cell 后,除了这个 cell 的其他地方都变暗。试了以下两个方法,都不太理想。

    1. 给其他所有 cell 上加一个 mask 层。但 iOS 7 现在 cell 之间有 separator,而且还有 inset,所以还要改 separator 的颜色和 inset,总之动画各种不舒服。而且卡。

    2. 直接在 [UIApplication sharedApplication].keyWindow 上加上下两个 mask。但这样 cell 移动的时候 mask 没法随之移动,非常蛋疼。

    大家有什么主意么?
    18 条回复    1970-01-01 08:00:00 +08:00
    i0xbean
        1
    i0xbean  
       2014-01-31 15:59:47 +08:00
    点击 cell 触发建立一个新的 window 过渡到上层,新 window 中有个『假 cell』处理后续操作。
    xhacker
        2
    xhacker  
    OP
       2014-01-31 16:12:35 +08:00
    @i0xbean: 我想同时实现在点击 cell 的时候把 cell 滚动到最上面,有什么好办法能让「假 cell」随之移动么?
    alexrezit
        3
    alexrezit  
       2014-01-31 16:27:10 +08:00
    我觉得亮的 cell 不是原来的 cell 吧...
    xhacker
        4
    xhacker  
    OP
       2014-01-31 17:27:38 +08:00
    @alexrezit: 如果是另外的 view,怎么能和 cell 非常好地同步滚到上面呢…
    alexrezit
        5
    alexrezit  
       2014-01-31 17:34:24 +08:00
    @xhacker
    不知道, 我都不记得 table view 怎么操作了. 自己写一个 transition 试试?
    icyalala
        6
    icyalala  
       2014-01-31 17:35:50 +08:00
    直接加到tableView上不行吗?
    PrideChung
        7
    PrideChung  
       2014-01-31 18:05:56 +08:00
    方案2,cell移动的时候调整mask不就行了
    so898
        8
    so898  
       2014-01-31 22:06:11 +08:00
    给UITableView加Mask啊,然后把UITabbar和UINavigationBar的mask也都加上不就完了……
    cameo
        9
    cameo  
       2014-01-31 23:24:41 +08:00
    方案1明显更自然。

    cell有没有mask,作为cell的一个属性写进model里,要加mask时修改model值然后[tableView reloadData]完事。各种卡很有可能是你的实现有问题,比如cell没做好复用。

    方案2仅仅从表现层做hack来实现,完全没有深入问题在model层次的本质,为了解决问题而解决问题,是非常糟糕的设计。
    xhacker
        10
    xhacker  
    OP
       2014-02-01 15:17:35 +08:00
    @so898: 怎么让某个 cell 不被 mask?
    xhacker
        11
    xhacker  
    OP
       2014-02-01 15:20:00 +08:00
    @cameo: cell 加上 mask,separator 的颜色还是不变的。而且 separator 的颜色好像不能在 animation block 里调整。我想要一个逐渐变黑的过程。
    xhacker
        12
    xhacker  
    OP
       2014-02-01 15:22:51 +08:00
    @icyalala: 怎么让某个 cell 不被 mask?
    @PrideChung: 怎么能动态监视 cell 的位置?
    so898
        13
    so898  
       2014-02-01 16:18:17 +08:00 via iPhone
    @xhacker 算高度……这种破事我经常干……
    xhacker
        14
    xhacker  
    OP
       2014-02-01 16:26:27 +08:00
    @so898: 那怎么跟着 cell 滚啊= =
    xhacker
        16
    xhacker  
    OP
       2014-02-01 17:58:02 +08:00
    @PrideChung: 我用 scrollToRowAtIndexPath:atScrollPosition:animated: 来把 row 滚动到最上面,不会调 scrollViewDidScroll:。
    so898
        17
    so898  
       2014-02-01 18:49:05 +08:00
    @xhacker 你把它添加到UITablView上面了,自然会跟着滚的啊
    xhacker
        18
    xhacker  
    OP
       2014-02-02 09:20:37 +08:00
    @so898: 有道理……我试试看。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   791 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 22:36 · PVG 06:36 · LAX 15:36 · JFK 18:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.