首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIStoryboardSegue:动画期间不显示视图

UIStoryboardSegue:动画期间不显示视图
EN

Stack Overflow用户
提问于 2015-06-08 17:04:34
回答 1查看 99关注 0票数 0

当执行自定义segue的动画时,目标视图显示为黑色。动画结束后,视图出现并看起来很好。

以下是截图:

动画场景:

在segue/动画完成后查看:

下面是自定义segue类:

代码语言:javascript
复制
class SegueToPreview: 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, screenHeight, screenWidth, screenHeight)

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

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

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

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

}

而放松海格的工作只是很好,显示两种观点。

我认为在执行动画时,视图没有加载,但不知道如何修复。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-08 18:28:42

目标vc视图的初始位置设置错误(假设您希望视图从右侧移动);您将其定位在屏幕下面,而不是屏幕的右侧,

代码语言:javascript
复制
secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)

这应该是,

代码语言:javascript
复制
secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30715082

复制
相关文章

相似问题

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