Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created July 3, 2014 14:08
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/58e82f259c80893ef1c9 to your computer and use it in GitHub Desktop.
Save Shilo/58e82f259c80893ef1c9 to your computer and use it in GitHub Desktop.
Category for Sparrow to fix stretching and center stage on auto rotation.
//
// 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;
CGFloat offsetLeft = -(self.width/2)*(widthRatio-1);
CGFloat offsetTop = -(self.height/2)*(heightRatio-1);
[support setupOrthographicProjectionWithLeft:offsetLeft right:(self.width*widthRatio)+offsetLeft top:offsetTop bottom:(self.height*heightRatio)+offsetTop];
}
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