I've got a UIImageView (full frame and rectangular) that i'm rotating with a CGAffineTransform. The UIImage of the UIImageView fills the entire frame. When the image is rotated and drawn the edges appear noticeably jagged. Is there anything I can do to make it look better? It's clearly not being anti-aliased with the background.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- SwiftUI: UIImage (QRCode) does not load after call
- how do you prevent page scroll in textarea on mobi
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Custom Marker performance iOS, crash with result “
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
New API – iOS 6/7
Also works for iOS 6, as noted by @Chris, but wasn't made public until iOS 7.
Since iOS 7, CALayer has a new property
allowsEdgeAntialiasing
which does exactly what you want in this case, without incurring the overhead of enabling it for all views in your application! This is a property of CALayer, so to enable this for a UIView you usemyView.layer.allowsEdgeAntialiasing = YES
.just add 1px transparent border to your image
The edges of CoreAnimation layers aren't antialiased by default on iOS. However, there is a key that you can set in Info.plist that enables antialiasing of the edges: UIViewEdgeAntialiasing.
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
If you don't want the performance overhead of enabling this option, a work-around is to add a 1px transparent border around the edge of the image. This means that the 'edges' of the image are no longer on the edge, so don't need special treatment!
Remember to set the appropriate anti-alias options:
I found this solution from here, and it's perfect:
usage:
The best way I've found to have smooth edges and a sharp image is to do this:
Adding the Info.plist key like some people describe has a big hit on performance and if you use that then you're basically applying it to everything instead of just the one place you need it.
Also, don't just use
UIGraphicsBeginImageContext(imageRect.size);
otherwise the layer will be blurry. You have to useUIGraphicsBeginImageContextWithOptions
like I've shown.