Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCoreAnimationExtras] Update documentation for resizbale images #trivial #492

Merged
merged 3 commits into from
Aug 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Source/Private/_ASCoreAnimationExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
@interface ASDisplayNode (ASResizableContents) <ASResizableContents>
@end

// This function can operate on either an ASDisplayNode (including un-loaded) or CALayer directly.
/**
This function can operate on either an ASDisplayNode (including un-loaded) or CALayer directly. More info about resizing mode: https://github.com/TextureGroup/Texture/issues/439

@param obj ASDisplayNode, CALayer or object that conforms to `ASResizableContents` protocol
@param image Image you would like to resize
*/
extern void ASDisplayNodeSetResizableContents(id<ASResizableContents> obj, UIImage *image);

/**
Expand Down
10 changes: 3 additions & 7 deletions Source/Private/_ASCoreAnimationExtras.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UI

extern void ASDisplayNodeSetResizableContents(id<ASResizableContents> obj, UIImage *image)
{
// FIXME: This method does not currently handle UIImageResizingModeTile, which is the default on iOS 6.
// I'm not sure of a way to use CALayer directly to perform such tiling on the GPU, though the stretch is handled by the GPU,
// and CALayer.h documents the fact that contentsCenter is used to stretch the pixels.

if (image) {
ASDisplayNodeCAssert(image.resizingMode == UIImageResizingModeStretch || UIEdgeInsetsEqualToEdgeInsets(image.capInsets, UIEdgeInsetsZero),
@"Image insets must be all-zero or resizingMode has to be UIImageResizingModeStretch. XCode assets default value is UIImageResizingModeTile which is not supported by Texture because of GPU-accelerated CALayer features.");

// Image may not actually be stretchable in one or both dimensions; this is handled
obj.contents = (id)[image CGImage];
obj.contentsScale = [image scale];
obj.rasterizationScale = [image scale];
CGSize imageSize = [image size];

ASDisplayNodeCAssert(image.resizingMode == UIImageResizingModeStretch || UIEdgeInsetsEqualToEdgeInsets(image.capInsets, UIEdgeInsetsZero),
@"the resizing mode of image should be stretch; if not, then its insets must be all-zero");

UIEdgeInsets insets = [image capInsets];

// These are lifted from what UIImageView does by experimentation. Without these exact values, the stretching is slightly off.
Expand Down