【问题标题】:Swift StackView interchange subview with animationSwift StackView 与动画交换子视图
【发布时间】:2018-01-07 15:47:45
【问题描述】:

如何使用动画制作堆栈交换的子视图

UIView.animateWithDuration(0.5, animations:
{
    self.stackview.exchangeSubviewAtIndex(3, withSubviewAtIndex: 4)
})

这在视图不在堆栈视图中时有效:

let lastXcoVar = lastView.center.x 

UIView.animateWithDuration(0.5, animations:
{
    lastView.center.x = nextView.center.x
    nextView.center.x = lastXcoVar
})

【问题讨论】:

    标签: ios swift animation subview stackview


    【解决方案1】:

    动画只是一种可视化。您可以做与不在堆栈视图中的视图相同的动画,在动画完成后,我们使用 exchangeSubviewAtIndex 来更新堆栈视图上的视图。例如:

    let lastXcoVar = lastView.center.x
    
    UIView.animateWithDuration(0.5, animations:
    {
        lastView.center.x = nextView.center.x
        nextView.center.x = lastXcoVar
    }) { _ in
        self.stackview.exchangeSubviewAtIndex(<index of lastView>, withSubviewAtIndex: <index of nextView>)
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 2021-02-18
      • 2012-03-19
      • 1970-01-01
      • 2012-05-06
      相关资源
      最近更新 更多