gpt4 book ai didi

快速,旋转 ImageView 并将旋转 ImageView 设置为 uibutton

转载 作者:行者123 更新时间:2023-11-30 10:08:17 29 4
gpt4 key购买 nike

我想单击按钮并用动画旋转其图像。动画完成后,我想为按钮设置新的旋转图像。然而,由于某种原因,旋转图像未设置为正常状态的按钮。它设置为突出显示状态。我有 bool 值 isPriceOrdered ,根据这个 bool 值我设置向上或向下箭头。这是一个代码:

   UIView.animateWithDuration(0.3, animations: {
self.buttonimage.imageView!.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}, completion: {
(success) in
if self.isPriceOrderAsc == true {
self.isPriceOrderAsc = false
let rotatedimage = UIImage(CGImage: (self.buttonimage.imageView!.image!.CGImage)!, scale: CGFloat(1.0), orientation: UIImageOrientation.DownMirrored)

self.buttonimage.setImage(rotatedimage, forState: .Normal)


}else{
self.isPriceOrderAsc = true
let rotatedimage = UIImage(CGImage: (self.buttonimage.imageView?.image!.CGImage)!, scale: CGFloat(1.0), orientation: UIImageOrientation.UpMirrored)

self.buttonimage.setImage(rotatedimage, forState: .Normal)
}
})

最佳答案

问题是我在转换图像之前没有保存按钮的原始转换。在变换图像度数之前保存变换后的原始图像。这是一段代码:

var originalTransform: CGAffineTransform?

UIView.animateWithDuration(0.3, animations: {

if self.buttonPriceOrder.imageView != nil {
originalTransform = self.buttonPriceOrder.imageView!.transform
self.buttonPriceOrder.imageView!.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}

}, completion: {
(success) in

if success {

self.buttonPriceOrder.imageView?.transform = originalTransform!

if self.isPriceOrderAsc == true {
self.isPriceOrderAsc = false
let rotatedimage = UIImage(CGImage: (self.buttonPriceOrder.imageView!.image!.CGImage)!, scale: CGFloat(1.0), orientation: UIImageOrientation.DownMirrored)
self.buttonPriceOrder.setImage(rotatedimage, forState: .Normal)

}else{
self.isPriceOrderAsc = true
let rotatedimage = UIImage(CGImage: (self.buttonPriceOrder.imageView?.image!.CGImage)!, scale: CGFloat(1.0), orientation: UIImageOrientation.UpMirrored)
self.buttonPriceOrder.imageView?.image = nil
self.buttonPriceOrder.setImage(rotatedimage, forState: .Normal)

}
self.isFilterActive = true
self.delegate.filterUpdated(self)
}

})

图像旋转后,在将图像设置为按钮之前,将按钮变换设置为原始图像。

关于快速,旋转 ImageView 并将旋转 ImageView 设置为 uibutton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34810423/

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