Search code examples
iosswiftrotationcgaffinetransform

UIView Rotation using swift issue


I would like to rotate UIView which defined on the storyboard I used

CGAffineTransform(rotationAngle: self.degreesToRadians(5))

which degreesToradians a function to convert to Radians, the rotation is working perfectly but the only problem is the UIView not vectorial (the edge of the view is not rendered properly and it looks like a saw) like in the screenshot below :

enter image description here


Solution

  • I have had the same problems as you and to solve it I just add a border to the view which is transparent, do it like this:

    customView.layer.borderWidth = 1
    customView.layer.borderColor = UIColor.clear.cgColor // important that it is clear
    customView.layer.shouldRasterize = true
    customView.layer.rasterizationScale = UIScreen.main.scale
    

    Add that code after your rotation code.

    With the code:
    enter image description here

    Without the code:
    enter image description here