Uiimageview를 20도 회전하려면 어떻게해야합니까?
-
21-08-2019 - |
문제
회전해야한다면 어떻게해야합니까? UIImageView
? 나는있다 UIImage
20도 회전하고 싶습니다.
Apple Docs는 변환 매트릭스에 대해 이야기하지만 어려운 것 같습니다. 이를 달성하기위한 유용한 방법이나 기능이 있습니까?
해결책
변환 매트릭스는 매우 어렵지 않습니다. 제공된 기능을 사용하면 매우 간단합니다.
imgView.transform = CGAffineTransformMakeRotation(.34906585);
(.34906585는 라디안에서 20도)
다른 팁
우회전하려면 왼쪽으로 회전하려면 값이 0보다 크지 않아야합니다. 예를 들어 -20.
CGFloat degrees = 20.0f; //the value in degrees
CGFloat radians = degrees * M_PI/180;
imageView.transform = CGAffineTransformMakeRotation(radians);
스위프트 4 :
let degrees: CGFloat = 20.0 //the value in degrees
let radians: CGFloat = degrees * (.pi / 180)
imageView.transform = CGAffineTransform(rotationAngle: radians)
스위프트 버전 :
let degrees:CGFloat = 20
myImageView.transform = CGAffineTransformMakeRotation(degrees * CGFloat(M_PI/180) )
스위프트 4.0
imageView.transform = CGAffineTransform(rotationAngle: CGFloat(20.0 * Double.pi / 180))
다음은 Swift 3의 확장입니다.
extension UIImageView {
func rotate(degrees:CGFloat){
self.transform = CGAffineTransform(rotationAngle: degrees * CGFloat(M_PI/180))
}
}
용법:
myImageView.rotate(degrees: 20)
_YourImageView.transform = CGAffineTransformMakeRotation(1.57);
여기서 1.57은 90도의 라디안 값입니다
이는 더 쉬운 서식 예제입니다 (20도).
CGAffineTransform(rotationAngle: ((20.0 * CGFloat(M_PI)) / 180.0))
내가 아는 한, 매트릭스 사용 UIAffineTransform
타사 프레임 워크의 도움없이 회전을 달성하는 유일한 방법입니다.
제휴하지 않습니다 StackOverflow