Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created July 2, 2014 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shilo/6d98cbf608158e512e04 to your computer and use it in GitHub Desktop.
Save Shilo/6d98cbf608158e512e04 to your computer and use it in GitHub Desktop.
Category for Sparrow to fix stretching on auto rotation. (Alternative)
//
// SPStage+AutoRotationFix.h
// Barebone
//
// Created by Shilo White on 7/2/14.
//
//
#import <Sparrow/Sparrow.h>
@interface SPStage (AutoRotationFix)
@end
//
// SPStage+AutoRotationFix.m
// Barebone
//
// Created by Shilo White on 7/2/14.
//
//
#import "SPStage+AutoRotationFix.h"
@implementation SPStage (AutoRotationFix)
- (void)render:(SPRenderSupport *)support
{
[SPRenderSupport clearWithColor:self.color alpha:1.0f];
CALayer *glLayer = [Sparrow currentController].view.layer;
if (glLayer.animationKeys)
{
CGSize glLayerSize = glLayer.bounds.size;
CGSize presentationLayerSize = ((CALayer *)glLayer.presentationLayer).bounds.size;
CGFloat widthRatio = presentationLayerSize.width/glLayerSize.width;
CGFloat heightRatio = presentationLayerSize.height/glLayerSize.height;
[support setupOrthographicProjectionWithLeft:0 right:self.width*widthRatio top:0 bottom:self.height*heightRatio];
}
else
[support setupOrthographicProjectionWithLeft:0 right:self.width top:0 bottom:self.height];
[super render:support];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment