UiView.animateWithDuration没有动画斯威夫特 [英] UiView.animateWithDuration Not Animating Swift

查看:564
本文介绍了UiView.animateWithDuration没有动画斯威夫特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面code动画搜索栏的显示/隐藏(搜索栏应该来自左,1-2秒内扩大到右)。然而,这并不动画和搜索栏立即显示,不管多少时间,我就把。我注意到以下几点:


  • 持续时间的不尊重

  • 甚至没有延迟尊重

  • 动画没有发生。组件会立即显示

     <$ C C> FUNC的CollectionView(的CollectionView:UICollectionView,didSelectItemAtIndexPath indexPath:NSIndexPath){
    // code获得选择的值...
    //隐藏集合视图,并显示搜索栏UIView.animateWithDuration(10.0,
        延迟:0.0,
        选项​​:UIViewAnimationOptions.TransitionCrossDissolve,
        动画:{
            self.searchBar.hidden = FALSE
            self.searchBar.frame = CGRectMake(0,0,300,44)//这也不起作用
        },
        完成:{(完:BOOL)在
            返回true
        })
    }


我使用X code 7,iOS的8和雨燕2.0​​。我见过其他的解决方案,但没有人对我的作品。好心帮...

更新:它曾与低于code。然而,它使用默认的动画选项 UIViewAnimationOptionCurveEaseInOut TransitionNone

  UIView.animateWithDuration(0.7,
                动画:{
                    self.searchBar.alpha = 1.0
                    self.searchBarRect.origin.x = self.searchBarRect.origin.x + 200
                    self.searchBar.frame = self.searchBarRect
                },
                完成:{(完:BOOL)在
                    返回true
            })


解决方案

在animateWithDuration之前,xPosition位置设置为-200和YPosition至-200。

像丹尼尔建议,你也需要改变,从1.0之外的东西阿尔法才能看到它淡出。

您使用自动布局?如果你是,你可能要动画的约束,而不是框架。

最后,你确定你已经正确连接了搜索栏?

编辑:PS,我会保持持续到像3.0或5.0。 10.0将永远需要和可能让你认为这是不是做,因为它需要多长时间什么。使3.0或5.0(最大)只是用于测试,然后降低到您想要的位置。

I am trying to animate show/hide of search bar using below code (The search bar should come from left and expand to right within 1-2 seconds). However, it doesn't animate and searchBar is immediately shown no matter how much time I put. I noticed following:

  • Duration is not respected
  • Not even delay is respected
  • Animation is not happening. Component is immediately shown

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    //code to get selected value...
    //Hide the collection view and show search bar
    
    UIView.animateWithDuration(10.0,
        delay: 0.0,
        options: UIViewAnimationOptions.TransitionCrossDissolve,
        animations: {
            self.searchBar.hidden = false
            self.searchBar.frame = CGRectMake(0, 0, 300, 44) //This doesn't work either
        },
        completion: { (finished: Bool) in
            return true
        })
    }
    

I am using Xcode 7, iOS 8 and Swift 2.0. I have seen at other solution, but none of them works for me. Kindly help...

Update: It worked with below code. However, it used default animation option of UIViewAnimationOptionCurveEaseInOut and TransitionNone

UIView.animateWithDuration(0.7,
                animations: {
                    self.searchBar.alpha = 1.0
                    self.searchBarRect.origin.x = self.searchBarRect.origin.x + 200
                    self.searchBar.frame = self.searchBarRect
                },
                completion: { (finished: Bool) in
                    return true
            })

解决方案

Before the animateWithDuration, set the XPosition to -200 and YPosition to -200.

Like Daniel Suggested, you need to also change the alpha from something other than 1.0 in order to see it "fade in".

Are you using autolayout? If you are, you may want to animate the constraints instead of the frame.

Finally, are you sure you've wired up the search bar properly?

Edit: PS, I would keep the duration to something like 3.0 or 5.0. 10.0 will take forever and may make you think that it isn't doing anything because of how long it takes. Make it 3.0 or 5.0 (max) just for testing and then decrease to where you want it.

这篇关于UiView.animateWithDuration没有动画斯威夫特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆