Last active
December 15, 2015 17:09
-
-
Save nielsbot/5294660 to your computer and use it in GitHub Desktop.
Make sure your layer is pixel-aligned when setting it's position. (Avoids things looking blurry)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// when setting the position of a layer, use this: | |
// layer.position = [ layer pixelAlignedPostionForPoint:<originalPoint> ] ; | |
@implementation CALayer (SetPositionPixelAligned) | |
-(CGPoint)pixelAlignedPositionForPoint:(CGPoint)p | |
{ | |
CGSize size = self.bounds.size ; | |
CGPoint anchorPoint = self.anchorPoint ; | |
CGPoint result = (CGPoint){ | |
roundf( p.x ) + anchorPoint.x * fmodf( size.width, 2.0f ) | |
, roundf( p.y ) + anchorPoint.y * fmodf( size.height,2.0f ) | |
} ; | |
return result; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment