如果进行两次变换,UISlider将不会移动

发布于 2025-01-09 02:01:21 字数 1173 浏览 1 评论 0原文

我有一个通过 Storyboard 实现的 UISlider。我添加了一个值为 1.57 的 Keypath layer.transform.rotation.z ,以使 UISlider 垂直。

我还有一个 MoveRight UIButton,它控制 3 个元素(两个 UIImageView 和一个 UISlider)一致移动。变换的代码如下所示,

      @IBAction func MoveRight(_ sender: Any) {
    // Used to Show Reset Button for Right
    ResetOrigin.isHidden = false
    let yPosition1 = myslider.frame.origin.y
    let yPosition2 = ImageView.frame.origin.y
    let yPosition3 = ImageView2.frame.origin.y
    
    UIView.animate(withDuration: 0.0, delay: 0.0, options: [], animations: {
        self.myslider.transform = CGAffineTransform(translationX: 0.001, y: yPosition1)
        self.ImageView.transform = CGAffineTransform(translationX: 0.001, y: yPosition2)
        self.ImageView2.transform = CGAffineTransform(translationX: 0.001, y: yPosition3)
    }, completion: nil)
    
}

当代码如下所示时,尽管 UISlider 在变换后不再是垂直的,但移动效果很好。当我尝试将这行代码添加到动画中时,

                self.myslider.transform = CGAffineTransform(rotationAngle: (CGFloat.pi / 2))

滑块将不再移动,而其他 2 个元素受到变换的影响。我尝试执行单独的 .animate 来查看是否可以解决问题,但给出了相同的结果。任何关于如何解决这个问题的想法将不胜感激

I have a UISlider that was implemented through Storyboard. I added a Keypath layer.transform.rotation.z with a value of 1.57 in order to make the UISlider vertical.

I also have a MoveRight UIButton that controls 3 elements (Two UIImageViews and One UISlider) to move in unison. The code for the transform is shown below

      @IBAction func MoveRight(_ sender: Any) {
    // Used to Show Reset Button for Right
    ResetOrigin.isHidden = false
    let yPosition1 = myslider.frame.origin.y
    let yPosition2 = ImageView.frame.origin.y
    let yPosition3 = ImageView2.frame.origin.y
    
    UIView.animate(withDuration: 0.0, delay: 0.0, options: [], animations: {
        self.myslider.transform = CGAffineTransform(translationX: 0.001, y: yPosition1)
        self.ImageView.transform = CGAffineTransform(translationX: 0.001, y: yPosition2)
        self.ImageView2.transform = CGAffineTransform(translationX: 0.001, y: yPosition3)
    }, completion: nil)
    
}

When the code is like this the movement works great although the UISlider is no longer Vertical after the transform. And when I try to add this line of code to the animation

                self.myslider.transform = CGAffineTransform(rotationAngle: (CGFloat.pi / 2))

The slider will no longer move while the other 2 Elements are affected by the transform. I tried doing a separate .animate to see if that would resolve the problem but the same result is given. Any ideas on how to solve this issue would be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文