Swift StackView与动画交换子视图

时间:2018-01-07 15:47:46

标签: ios swift animation subview stackview

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

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
})

1 个答案:

答案 0 :(得分:1)

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

CREATE TABLE `Collaboration_Collaborator` (
  `Collaboration_id` int(11) NOT NULL,
  `collaborators_id` int(11) NOT NULL,
  UNIQUE KEY `UK_obmdv02oey7264a085m7baqbo` (`collaborators_id`),
  KEY `FKlrsiogs304faydykt1xtgpk9k` (`Collaboration_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;