Created
July 3, 2014 14:08
-
-
Save Shilo/58e82f259c80893ef1c9 to your computer and use it in GitHub Desktop.
Category for Sparrow to fix stretching and center stage on auto rotation.
This file contains 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
// | |
// SPStage+AutoRotationFix.h | |
// Barebone | |
// | |
// Created by Shilo White on 7/2/14. | |
// | |
// | |
#import <Sparrow/Sparrow.h> | |
@interface SPStage (AutoRotationFix) | |
@end |
This file contains 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
// | |
// 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