【发布时间】:2016-01-20 03:55:13
【问题描述】:
在名为“courseView”的 UIView 顶部,我有一个带有名为“展开按钮”的条形按钮的工具栏。当我按下该按钮时,将调用 expandCourseView() 并且视图框架会正确设置动画。然而,在动画完成后,我想用“expandButton”来改变文本。当它执行此操作时,视图的框架会自动捕捉回其原始形状。为什么会这样?似乎工具栏上的按钮没有记录其位置已移动。
@IBOutlet weak var expandButton: UIBarButtonItem!
@IBAction func expandButton(sender: AnyObject) {
expandCourseView()
}
func expandCourseView(){
let width = self.courseView.frame.width
let height = self.courseView.frame.height
let frameOffset : CGFloat = 200
UIView.animateWithDuration(0.5, animations: { () -> Void in
if (height < 211){
self.courseView.frame = CGRect(x: self.courseView.frame.minX, y: self.courseView.frame.minY - frameOffset, width: width, height: height + frameOffset)
}
else {
self.courseView.frame = CGRect(x: self.courseView.frame.minX, y: self.courseView.frame.minY + frameOffset, width: width, height: height - frameOffset)
}
}) { (value: Bool) -> Void in
if height < 211{
self.expandButton.title = "Close"
} else {
self.expandButton.title = "Expand"
}
}
}
【问题讨论】:
标签: xcode swift animation uibarbuttonitem uitoolbar