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
georgetso
V2EX  ›  iDev

有个 interactive transition 的问题请教

  •  
  •   georgetso · 2016-01-20 10:40:25 +08:00 · 1550 次点击
    这是一个创建于 3034 天前的主题,其中的信息可能已经有所发展或是发生改变。
    代码地址: http://pan.baidu.com/s/1qX5hV6O

    可以看到,当上下拖动红色的呈现一半的 VC 时,后面白色的 VC 的 alpha 并没有跟着变化。
    为啥?怎么解决?
    第 1 条附言  ·  2016-01-20 12:21:10 +08:00
    下载代码,运行,向下拖动红色的 view controller ,背后白色的 view controller 的 alpha 没有跟着你的动作变化。也就是说 alpha 变化不是 interactive 的,我想知道为啥。
    4 条回复    2016-01-20 11:46:19 +08:00
    lxian2
        1
    lxian2  
       2016-01-20 10:49:24 +08:00
    没太明白你的问题呀
    georgetso
        2
    georgetso  
    OP
       2016-01-20 10:51:25 +08:00
    @lxian2 下载代码,运行,向下拖动红色的 view controller ,背后白色的 view controller 的 alpha 没有跟着你的动作变化。也就是说 alpha 变化不是 interactive 的,我想知道为啥。
    lxian2
        3
    lxian2  
       2016-01-20 11:45:03 +08:00   ❤️ 1
    我认为原因是 dismiss 的时候 animateTransition 里面没有设置 transitionContext.containerView()
    改成
    ```
    if let toVC = toVC, toView = toVC.view, fromVC = fromVC, fromView = fromVC.view {
    if isPresenting {
    var frame = transitionContext.initialFrameForViewController(fromVC)
    frame.origin.y = frame.size.height
    toView.frame = frame
    transitionContext.containerView()?.addSubview(toView)
    } else {
    toView.frame = transitionContext.finalFrameForViewController(toVC)
    fromView.frame = transitionContext.initialFrameForViewController(fromVC)
    print(toView.frame, fromView.frame)
    transitionContext.containerView()?.addSubview(toView)
    transitionContext.containerView()?.addSubview(fromView)
    toView.alpha = 0.5
    toView.transform = CGAffineTransformMakeScale(0.98, 0.98)
    }
    }
    ```
    就可以看到你想要的效果了
    lxian2
        4
    lxian2  
       2016-01-20 11:46:19 +08:00
    vc.modalPresentationStyle = .Custom
    然后这个如果设置成.Custom 的话需要自己实现一个 UIPresentationController
    http://stackoverflow.com/questions/24338700/from-view-controller-disappears-using-uiviewcontrollercontexttransitioning/25775726#25775726
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1315 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 17:57 · PVG 01:57 · LAX 10:57 · JFK 13:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.