1
我有一個平移和旋轉手勢的圖像視圖。平移和旋轉功能的預期,但在某些時候,我必須在更改圖像時將圖像視圖恢復到其初始位置。爲此,我將圖像視圖的框架再次設置爲舊框架。的幀被設置但圖像有時縮小。任何幫助表示讚賞。旋轉 代碼如下UIImageView旋轉問題iOS
@objc fileprivate func handleRotationGesture1(sender:UIRotationGestureRecognizer)
{
if sender.state == .began || sender.state == .changed {
sender.view?.transform = (sender.view?.transform.rotated(by: sender.rotation))!
sender.rotation = 0
}
}
func repositionImages()
{
imageView1.frame = imageView1Frame
imageView2.frame = imageView2Frame
imageView1.transform = CGAffineTransform.init(rotationAngle: 0)
imageView2.transform = CGAffineTransform.init(rotationAngle: 0)
imageView1.image = UIImage.init(cgImage: (image1.cgImage)!, scale: (image1.scale), orientation: .up)
imageView2.image = UIImage.init(cgImage: (image2.cgImage)!, scale: (image2.scale), orientation: .up)
}
不工作的傢伙:( – jegadeesh
感謝您的幫助。它工作正常,但我在設置框架時錯誤地將圖像應用到圖像視圖 – jegadeesh
很高興我能幫上忙! –