gpt4 book ai didi

ios - UITableView 宽度动画时 UITableViewCell 中的 UIButton 跳转

转载 作者:行者123 更新时间:2023-12-03 16:12:32 24 4
gpt4 key购买 nike

当执行动画以减小 tableview 宽度时,垃圾桶按钮会在动画实际开始之前先跳到左侧。动画在 ViewController 中执行。

UIView.Animate(0.05d, 0.15d, UIViewAnimationOptions.CurveEaseInOut, () =>
{
OrderProductsTableView.Frame = new CGRect(LeftPanel.Frame.Width + 130f, OrderProductsTableView.Frame.Location.Y, View.Frame.Size.Width - LeftAddProductPanel.Frame.Width, OrderProductsTableView.Frame.Size.Height);
RightPanelFooter.Alpha = 0;
}, null);

before

之后: after

按钮有一个约束,因此它始终距离表格 View 单元格(xib)的右侧 8 px。

我想要/期望的是按钮随着 tableview 宽度变化的动画及时滑动。我是否错误地认为自动布局会解决这个问题?

我可以在 tableview 上调用 reloadData() 并在 cellForRowAtIndexPath 中手动重新定位按钮,但我希​​望有一种稍微更优雅的方式。

最佳答案

您还需要为按钮设置动画。您可以通过以下方式获取对您的单元格的引用:

List<UITableViewCell> cells = OrderProductsTableView.VisibleCells.ToList();

然后循环遍历单元格并修改x位置,例如:

UIView.Animate(0.05d, 0.15d, UIViewAnimationOptions.CurveEaseInOut, () =>
{
foreach (UITableViewCell cell in cells)
{
MyCellType mCell = cell as MyCellType;
mCell.trashButton.Frame = new CGRect(newXValue, newYValue, newWidthValue, newHeightValue);
}

}, null);

然后像您已经完成的那样设置表格 View 宽度的动画。动画应该同时运行,并且您的按钮应该随着 Table View 宽度的动画移动。

关于ios - UITableView 宽度动画时 UITableViewCell 中的 UIButton 跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40864966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com