【问题标题】:change UIbutton inside animation block using swift使用swift更改动画块内的UIbutton
【发布时间】:2015-01-03 15:15:08
【问题描述】:

您好,我是 swift 新手,我正在尝试创建一组动画并更改 uibutton 内的图像。问题是它弄乱了动画。我错过了什么?谢谢

如您所见,当按下按钮时,我正在调整一些 uiTableView 和 uiViews 的高度

所以我有一个带有向上箭头的按钮,当动画完成后,我想用不同的图像更改指向下方的箭头

当我删除 uibutton 设置动画时,动画被搞砸了,当我添加这一行时,动画工作正常,一切从头开始。

这段代码有问题吗?

 UIView.animateWithDuration(0.4, delay: 0.1, options: .CurveEaseOut, animations: {

     //changing the heights of scroll view and few tables
     self.WeatherScrollView.frame = CGRect(x:0, y:0, width: screenSize.width, height: 44)
     self.WeatherSubView.hidden = true;

     self.NavbarSubView.frame = CGRect(x:0, y:100, width: screenSize.width, height: 44)
     self.apiView.frame = CGRect(x:0, y:145, width: screenSize.width, height: 50)
     self.SearchResultsTable.frame = CGRect(x:0, y:195, width: screenSize.width, height:screenSize.height-196 )
     self.smallHeaderView.frame = CGRect(x:0, y:44, width: screenSize.width, height:60 )

 }, completion: { finished in
     //the problem is here 
     //the button is inside NavbarSubView that is also being animated if its matters
     self.slideBtn.setImage(UIImage(named: "arrow_open") ,forState:UIControlState.Normal)            
})

【问题讨论】:

  • 你想通过动画实现什么?
  • 请更好地描述您想要实现的目标和实际获得的目标。动画怎么搞的?

标签: ios animation swift uibutton uikit


【解决方案1】:

我通过在 viewDidLayoutSubviews 中添加一些布局代码解决了这个问题

override func viewDidLayoutSubviews() {

    if ScreenState == true {
        //some repositioning of whatever
        self.screenDevider("open",animate: false);
    }
}

【讨论】:

    猜你喜欢
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多