如果进行两次变换,UISlider将不会移动
我有一个通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论