gpt4 book ai didi

ios - 水平滑入式菜单

转载 作者:行者123 更新时间:2023-11-29 00:03:34 24 4
gpt4 key购买 nike

我是 iOS/Swift 开发的新手,我正在尝试实现水平滑入式菜单(用于用户设置)。

我已经设法让它工作了,我面临的问题是,菜单是从右向左滑动的,但它应该反过来,即从左向右滑动。我尝试过使用正值和负值,但我仍然对这些 CG 属性(x 轴、y 轴等)的工作原理感到有些困惑。

这是我的代码,负责显示菜单:

     private func showSettingsMenu(){
if let window = UIApplication.shared.keyWindow {

blackView.backgroundColor = UIColor(white: 0, alpha: 0.7)

blackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleDismiss)))

window.addSubview(blackView)
window.addSubview(collectionView)

blackView.frame = window.frame
blackView.alpha = 0

let collectionWidth: CGFloat = window.frame.width * 0.75
let x = window.frame.width - collectionWidth

collectionView.frame = CGRect(x: window.frame.width, y: 0, width: collectionWidth, height: window.frame.height)

UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {

self.blackView.alpha = 1
self.collectionView.frame = CGRect(x: x, y: 0, width: self.collectionView.frame.width, height: self.collectionView.frame.height)

}, completion: nil)
}
}

最佳答案

问题是您将初始 x 位置设置为屏幕宽度,将最终 x 位置设置为屏幕宽度的 1/4,以便它从右向左滑动:

let collectionWidth: CGFloat = window.frame.width * 0.75

collectionView.frame = CGRect(x: -1 * collectionWidth , y: 0, width: collectionWidth, height: window.frame.height)

UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {

self.blackView.alpha = 1

self.collectionView.frame = CGRect(x: 0, y: 0, width: self.collectionView.frame.width, height: self.collectionView.frame.height)

}, completion: nil)

编辑更改行

 collectionView.frame = CGRect(x: window.frame.width, y: 0, width: collectionWidth, height: window.frame.height)

collectionView.frame = CGRect(x: -1 * collectionWidth , y: 0, width: collectionWidth, height: window.frame.height)

///动画内部换线

 self.collectionView.frame = CGRect(x: x, y: 0, width: self.collectionView.frame.width, height: self.collectionView.frame.height)

 self.collectionView.frame = CGRect(x: 0, y: 0, width: self.collectionView.frame.width, height: self.collectionView.frame.height)

关于ios - 水平滑入式菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48747623/

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