首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIStoryboardSegue:顶部视图没有向下滑动

UIStoryboardSegue:顶部视图没有向下滑动
EN

Stack Overflow用户
提问于 2015-08-04 08:20:59
回答 2查看 103关注 0票数 1

我有以下的快速代码,我正在努力实现的是一个从顶部滑落的海格。我希望secondVCView在firstVCView下面,并让firstVCView从显示secondVCView的幻灯片中滑出。

目前没有动画,它只是闪烁到secondVCView。

非常感谢

代码语言:javascript
复制
import UIKit

class TopToBottomSegue: UIStoryboardSegue {

override func perform() {

    // Assign the source and destination views to local variables.
    var firstVCView = self.sourceViewController.view as UIView!
    var secondVCView = self.destinationViewController.view as UIView!

    // Get the screen width and height.
    let screenWidth = UIScreen.mainScreen().bounds.size.width
    let screenHeight = UIScreen.mainScreen().bounds.size.height

    // Specify the initial position of the destination view.
    secondVCView.frame = CGRectMake(0, 0, screenWidth, screenHeight)

    // Access the app's key window and insert the destination view below the current (source) one.
    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(secondVCView, belowSubview: firstVCView)

    // Animate the transition.
    UIView.animateWithDuration(0.4, animations: { () -> Void in

        firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, screenHeight)
        //secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)

        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                animated: false,
                completion: nil)
    }

  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-04 20:38:06

我不确定这是否是正确的方法,但我设法使它工作,插入两个视图。

--

代码语言:javascript
复制
import UIKit

class TopToBottomSegue: UIStoryboardSegue {

override func perform() {
    // Assign the source and destination views to local variables.
    let firstVCView = self.sourceViewController.view as UIView!
    let secondVCView = self.destinationViewController.view as UIView!

    // Get the screen width, height and status bar height.
    let screenWidth = UIScreen.mainScreen().bounds.size.width
    let screenHeight = UIScreen.mainScreen().bounds.size.height
    let statusBarHeight = self.statusBarHeight()

    // Specify the initial position of both views.
    secondVCView.frame = CGRectMake(0.0, 0.0, screenWidth, screenHeight)
    firstVCView.frame = CGRectMake(0.0, statusBarHeight, screenWidth, screenHeight)

    // Access the app's key window and insert the destination view below the current (source) one.
    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(firstVCView, aboveSubview: secondVCView)
    window?.insertSubview(secondVCView, belowSubview: firstVCView)

    // Animate the transition.
    UIView.animateWithDuration(0.3, animations: { () -> Void in

        firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, screenHeight)

        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as UIViewController,
                animated: false,
                completion: nil)
    }

}
func statusBarHeight() -> CGFloat {
    let statusBarSize = UIApplication.sharedApplication().statusBarFrame.size
    return Swift.min(statusBarSize.width, statusBarSize.height)
}
}
票数 0
EN

Stack Overflow用户

发布于 2015-08-04 08:28:57

据我所知,为了获得流畅的动画,您需要在layoutIfNeed块中调用animateWithduration。

问候

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31804175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档