如何快速从左侧滑动和滑动菜单? 以下代码在左侧显示菜单,但是当slideIn快速发生并且实际上没有显示菜单来自左侧时。另外,SlideOut从右侧而不是左侧关闭菜单。
这是我的代码:
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
self.blackView.alpha = 1
self.collectionView.frame = CGRect(x: 0, y: 0, width:
self.collectionView.frame.width - 10, height:
self.collectionView.frame.height)
}, completion: nil)
,也适用于slideOut
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.collectionView.frame = CGRect(x: window.frame.width, y: 0, width: self.collectionView.frame.width, height: self.collectionView.frame.height)
}
}) { (completed: Bool)
任何建议表示赞赏。
答案 0 :(得分:0)
//Slide in
self.collectionView.frame = CGRect(x: -(window.frame.width), y: 0, width: window.frame.width-50, height: window.frame.height)
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
self.blackView.alpha = 1
self.collectionView.frame = CGRect(x: 0, y: 0, width: window.frame.width-50, height: window.frame.height)
}, completion: nil)
//Slide out
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.collectionView.frame = CGRect(x: -(window.frame.width), y: 0, width: window.frame.width-50, height: window.frame.height)
}
}, completion: nil)