V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
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 · Jan 31, 2014 · 5273 views
    This topic created in 4480 days ago, the information mentioned may be changed or developed.
    大概就是 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 replies    1970-01-01 08:00:00 +08:00
    i0xbean
        1
    i0xbean  
       Jan 31, 2014
    点击 cell 触发建立一个新的 window 过渡到上层,新 window 中有个『假 cell』处理后续操作。
    xhacker
        2
    xhacker  
    OP
       Jan 31, 2014
    @i0xbean: 我想同时实现在点击 cell 的时候把 cell 滚动到最上面,有什么好办法能让「假 cell」随之移动么?
    alexrezit
        3
    alexrezit  
       Jan 31, 2014
    我觉得亮的 cell 不是原来的 cell 吧...
    xhacker
        4
    xhacker  
    OP
       Jan 31, 2014
    @alexrezit: 如果是另外的 view,怎么能和 cell 非常好地同步滚到上面呢…
    alexrezit
        5
    alexrezit  
       Jan 31, 2014
    @xhacker
    不知道, 我都不记得 table view 怎么操作了. 自己写一个 transition 试试?
    icyalala
        6
    icyalala  
       Jan 31, 2014
    直接加到tableView上不行吗?
    PrideChung
        7
    PrideChung  
       Jan 31, 2014
    方案2,cell移动的时候调整mask不就行了
    so898
        8
    so898  
       Jan 31, 2014
    给UITableView加Mask啊,然后把UITabbar和UINavigationBar的mask也都加上不就完了……
    cameo
        9
    cameo  
       Jan 31, 2014
    方案1明显更自然。

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

    方案2仅仅从表现层做hack来实现,完全没有深入问题在model层次的本质,为了解决问题而解决问题,是非常糟糕的设计。
    xhacker
        10
    xhacker  
    OP
       Feb 1, 2014
    @so898: 怎么让某个 cell 不被 mask?
    xhacker
        11
    xhacker  
    OP
       Feb 1, 2014
    @cameo: cell 加上 mask,separator 的颜色还是不变的。而且 separator 的颜色好像不能在 animation block 里调整。我想要一个逐渐变黑的过程。
    xhacker
        12
    xhacker  
    OP
       Feb 1, 2014
    @icyalala: 怎么让某个 cell 不被 mask?
    @PrideChung: 怎么能动态监视 cell 的位置?
    so898
        13
    so898  
       Feb 1, 2014 via iPhone
    @xhacker 算高度……这种破事我经常干……
    xhacker
        14
    xhacker  
    OP
       Feb 1, 2014
    @so898: 那怎么跟着 cell 滚啊= =
    xhacker
        16
    xhacker  
    OP
       Feb 1, 2014
    @PrideChung: 我用 scrollToRowAtIndexPath:atScrollPosition:animated: 来把 row 滚动到最上面,不会调 scrollViewDidScroll:。
    so898
        17
    so898  
       Feb 1, 2014
    @xhacker 你把它添加到UITablView上面了,自然会跟着滚的啊
    xhacker
        18
    xhacker  
    OP
       Feb 2, 2014
    @so898: 有道理……我试试看。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3304 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 12:54 · PVG 20:54 · LAX 05:54 · JFK 08:54
    ♥ Do have faith in what you're doing.