Skip to content

Commit

Permalink
customised the orientation behaviour for the AppViewControllers
Browse files Browse the repository at this point in the history
  • Loading branch information
julapy committed Feb 8, 2012
1 parent 38e703d commit 686836b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 54 deletions.
10 changes: 5 additions & 5 deletions example/emptyExample.xcodeproj/project.pbxproj
Expand Up @@ -152,14 +152,14 @@
150FA5F914E2157000512910 /* AppViewControllers */ = {
isa = PBXGroup;
children = (
150FA5FA14E2157000512910 /* CircleAppViewController.h */,
150FA5FB14E2157000512910 /* CircleAppViewController.mm */,
150FA5FC14E2157000512910 /* ImageAppViewController.h */,
150FA5FD14E2157000512910 /* ImageAppViewController.mm */,
150FA5FE14E2157000512910 /* SquareAppViewController.h */,
150FA5FF14E2157000512910 /* SquareAppViewController.mm */,
150FA5FA14E2157000512910 /* CircleAppViewController.h */,
150FA5FB14E2157000512910 /* CircleAppViewController.mm */,
150FA60014E2157000512910 /* TriangleAppViewController.h */,
150FA60114E2157000512910 /* TriangleAppViewController.mm */,
150FA5FC14E2157000512910 /* ImageAppViewController.h */,
150FA5FD14E2157000512910 /* ImageAppViewController.mm */,
);
path = AppViewControllers;
sourceTree = "<group>";
Expand All @@ -179,9 +179,9 @@
isa = PBXGroup;
children = (
15F4289E1498176E00412037 /* main.mm */,
150FA60614E2157C00512910 /* UI */,
150FA5EC14E214F500512910 /* Apps */,
150FA5F914E2157000512910 /* AppViewControllers */,
150FA60614E2157C00512910 /* UI */,
);
path = src;
sourceTree = "<group>";
Expand Down
35 changes: 1 addition & 34 deletions example/src/AppViewControllers/CircleAppViewController.mm
Expand Up @@ -20,40 +20,7 @@ - (id) initWithFrame : (CGRect)frame app:(ofBaseApp*)app

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
BOOL bRotate = NO;
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft );
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationLandscapeRight );
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationPortrait );
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );

return bRotate;
}

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect screen;
CGFloat rotate;
CGPoint center;

screen = [[ UIScreen mainScreen ] bounds ];
center = CGPointMake( screen.size.width * 0.5, screen.size.height * 0.5 ); // default is portrait.
if( UIInterfaceOrientationIsLandscape( toInterfaceOrientation ) )
center = CGPointMake( screen.size.height * 0.5, screen.size.width * 0.5 ); // if landscape, flip width and height.

rotate = 0;
if( toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft )
rotate = PI * 0.5;
else if( toInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
rotate = -PI * 0.5;
else if( toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown )
rotate = -PI;

[UIView beginAnimations:@"counter_orientate_glView" context:nil];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.glView.transform = CGAffineTransformMakeRotation( rotate );
self.glView.center = center;
[UIView commitAnimations];
return NO;
}

@end
21 changes: 6 additions & 15 deletions example/src/AppViewControllers/TriangleAppViewController.mm
Expand Up @@ -13,18 +13,18 @@ @implementation TriangleAppViewController

- (id) initWithFrame : (CGRect)frame app:(ofBaseApp*)app
{
ofxiPhoneGetOFWindow()->setOrientation( OF_ORIENTATION_DEFAULT ); //-- default portait orientation.
ofxiPhoneGetOFWindow()->setOrientation( OF_ORIENTATION_90_RIGHT ); //-- load app in landscape mode.

return self = [ super initWithFrame:frame app:app ];
self = [ super initWithFrame:frame app:app ];

return self;
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
BOOL bRotate = NO;
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft );
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationLandscapeRight );
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationPortrait );
bRotate = bRotate || ( toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );

return bRotate;
}
Expand All @@ -36,17 +36,8 @@ - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOri
CGPoint center;

screen = [[ UIScreen mainScreen ] bounds ];
center = CGPointMake( screen.size.width * 0.5, screen.size.height * 0.5 ); // default is portrait.
if( UIInterfaceOrientationIsLandscape( toInterfaceOrientation ) )
center = CGPointMake( screen.size.height * 0.5, screen.size.width * 0.5 ); // if landscape, flip width and height.

rotate = 0;
if( toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft )
rotate = PI * 0.5;
else if( toInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
rotate = -PI * 0.5;
else if( toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown )
rotate = -PI;
center = CGPointMake( screen.size.height * 0.5, screen.size.width * 0.5 );
rotate = PI * 0.5;

[UIView beginAnimations:@"counter_orientate_glView" context:nil];
[UIView setAnimationDuration:duration];
Expand Down

0 comments on commit 686836b

Please sign in to comment.