Ios 水平滑入菜单

Ios 水平滑入菜单,ios,swift4,xcode9.2,Ios,Swift4,Xcode9.2,我对iOS/Swift开发非常陌生,我正在尝试为用户设置实现一个水平滑入菜单 我已经设法使它工作,我面临的问题是,菜单从右向左滑动,但它应该反过来,即从左向右。我尝试过使用正值和负值,但我仍然对这些CG属性如何在x轴、y轴等轴上工作感到困惑 这是我的代码,负责显示菜单: private func showSettingsMenu(){ if let window = UIApplication.shared.keyWindow { blackView.

我对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)

///内部动画更改线

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


您可以提供修复吗?答案包含修复更改x此处collectionView.frame=CGRectx:-1*collectionWidth,y:0,width:collectionWidth,height:window.frame.height,在UIView.animate之前的行中
 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)