【发布时间】:2015-10-27 14:34:59
【问题描述】:
我想在表格视图单元格内转换视图。更准确地说,当用户单击 UITableViewCell 中的按钮时,视图应从单元格的右侧滑入,并且当用户单击滑动视图中的按钮时,该视图应滑回其原始位置。除了将滑动视图发送回其原始位置的动画之外,我可以完成所有这些操作。
为了实现这一点,我到目前为止所做的是,为表格视图单元格创建了一个 xib 文件,其中包含并排的两个视图,让它是 view1 和 view2。当 tableview 加载到屏幕时,只有 view1 对用户可见。并将 view1.trailingedge 和 view2.leadingedge 的自动布局约束设置为 0,该约束连接到 cell.swift 并命名为 leftConstraint。现在,当单击 view1 中的按钮时,view2 使用以下代码从单元格的右侧滑入:-
self.view2.transform = CGAffineTransformMakeTranslation(UIScreen.mainScreen().bounds.width, 0)
UIView.animateWithDuration(0.4, animations: { () -> Void in
self.view2.transform = CGAffineTransformIdentity
self.leftConstraint.constant -= UIScreen.mainScreen().bounds.width
})
当试图将 view2 发送回其旧位置时(这应该发生在单击 view2 中的按钮时),即。单元格动画的右侧不起作用,view2 中的所有元素都消失了。使用以下代码将视图发送到单元格的右侧:-
self.view2.transform = CGAffineTransformMakeTranslation(UIScreen.mainScreen().bounds.width, 0)
UIView.animateWithDuration(0.4, animations: { () -> Void in
self.view2.transform = CGAffineTransformIdentity
self.leftConstraint.constant += UIScreen.mainScreen().bounds.width
})
在此先感谢您的帮助。特别感谢@MarkHim 的帮助。
【问题讨论】:
标签: ios uitableview animation uiview cgaffinetransform