Ios 向上动画而不填充屏幕的视图

Ios 向上动画而不填充屏幕的视图,ios,swift,uiview,Ios,Swift,Uiview,这就是我想做的: 以下是初始屏幕: 单击指向底部的箭头时,会出现一个较小的视图,从底部向顶部过渡,如下所示: 正如你所看到的,后面的视图变暗了。当我点击后视图时,较小尺寸的视图通过向下设置动画而消失 我尝试了几件事: 1.我试着分段,这似乎是正确的动画,即从下到上,但它涵盖了整个后视图。 2.我试图通过复制此帖子,使模式视图仅为父视图大小的一半:。然而,它没有起作用。 3.因此,我决定在后视图的顶部放置一个UIView,如下所示: 我将灰色视图与@ibvar-messageView:UIV

这就是我想做的:

以下是初始屏幕:

单击指向底部的箭头时,会出现一个较小的视图,从底部向顶部过渡,如下所示:

正如你所看到的,后面的视图变暗了。当我点击后视图时,较小尺寸的视图通过向下设置动画而消失

我尝试了几件事: 1.我试着分段,这似乎是正确的动画,即从下到上,但它涵盖了整个后视图。 2.我试图通过复制此帖子,使模式视图仅为父视图大小的一半:。然而,它没有起作用。 3.因此,我决定在后视图的顶部放置一个UIView,如下所示:


我将灰色视图与
@ibvar-messageView:UIView连接起来。我尝试使用以下代码:
UIView.transitionWithView(messageView,持续时间:1.0,选项:uiviewmanimationoptions.CurveEaseIn,animations:nil,completion:nil)
。然而,似乎什么也没有发生。关于如何实现这一点,有什么建议吗?

有关按钮的动画:

将自动布局约束添加到BottomLayout指南。并创建一个IBOutlet作为

@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
var shouldAnimateView:Bool = true
在按钮的操作上,需要使用约束设置视图的动画

@IBAction func showOrHideViewBtn(sender: AnyObject) {

    if shouldAnimateView {
        self.bottomConstraint.constant = self.view.frame.size.height/2+5
         UIView.animateWithDuration(Double(0.2), animations: {
            self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height
            self.view.layoutIfNeeded()
        })


    }else{

        self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height
        UIView.animateWithDuration(Double(0.2), animations: {
            self.bottomConstraint.constant =  self.view.frame.size.height/2+5
            self.view.layoutIfNeeded()
        })


    }
    shouldAnimateView = !shouldAnimateView

}

按钮的动画:

将自动布局约束添加到BottomLayout指南。并创建一个IBOutlet作为

@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
var shouldAnimateView:Bool = true
在按钮的操作上,需要使用约束设置视图的动画

@IBAction func showOrHideViewBtn(sender: AnyObject) {

    if shouldAnimateView {
        self.bottomConstraint.constant = self.view.frame.size.height/2+5
         UIView.animateWithDuration(Double(0.2), animations: {
            self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height
            self.view.layoutIfNeeded()
        })


    }else{

        self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height
        UIView.animateWithDuration(Double(0.2), animations: {
            self.bottomConstraint.constant =  self.view.frame.size.height/2+5
            self.view.layoutIfNeeded()
        })


    }
    shouldAnimateView = !shouldAnimateView

}

为什么您的动画在
transitionWithView
中为
nil
??假设你把你的动画代码放在那里,比如改变你想让它动画的子视图的偏移量,然后它就会开始。如果您希望后屏幕淡入灰色,并从下方按下小菜单,最简单的方法是首先在
动画
块中创建它们,但将其隐藏,然后在
transitionWithView
中取消隐藏并更改它们的偏移??假设你把你的动画代码放在那里,比如改变你想让它动画的子视图的偏移量,然后它就会开始。如果您希望后屏幕淡入灰色,并从下方按下小菜单,最简单的方法是首先在
动画中创建它们,但将其隐藏,然后取消隐藏并更改其偏移