Skip to content

Instantly share code, notes, and snippets.

@epologee
Created February 17, 2011 13:26
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 epologee/b8670e5976635a629842 to your computer and use it in GitHub Desktop.
Save epologee/b8670e5976635a629842 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@interface AbstractViewController : UIViewController
@end
#import "AbstractViewController.h"
@implementation AbstractViewController
- (void)loadView {
self.view = [[[UIView alloc] init] autorelease];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(50, 10, 200, 50)] autorelease];
label.numberOfLines = 2;
label.text = [[[self class] description] stringByAppendingFormat:@"\nAccept landscape: %@", [self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft] ? @"YES" : @"NO"];
[self.view addSubview:label];
}
-(void)viewWillAppear:(BOOL)animated {
NSLog(@"%@ appeared with app frame %@ vs self.frame %@", [[self class] description], NSStringFromCGRect([[UIScreen mainScreen] applicationFrame]), NSStringFromCGRect(self.view.frame));
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
DLog(@"%@ from %i", self, fromInterfaceOrientation);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
#import <UIKit/UIKit.h>
@interface DeviceRotationAppDelegate : NSObject <UIApplicationDelegate>
@end
#import "DeviceRotationAppDelegate.h"
#import "FirstViewController.h"
@interface DeviceRotationAppDelegate ()
@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) UIWindow *window;
@end
@implementation DeviceRotationAppDelegate
@synthesize window=_window, navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FirstViewController *fvc = [[[FirstViewController alloc] init] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:fvc] autorelease];
self.navigationController.navigationBarHidden = YES;
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
self.navigationController = nil;
self.window = nil;
[super dealloc];
}
@end
#import <UIKit/UIKit.h>
#import "AbstractViewController.h"
@interface FirstViewController : AbstractViewController
@end
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation FirstViewController
-(void)loadView {
[super loadView];
UIView *nextButton = [[[UIView alloc] initWithFrame:CGRectMake(10, 40, 25, 25)] autorelease];
nextButton.backgroundColor = [UIColor orangeColor];
[nextButton addGestureRecognizer:[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushNext)] autorelease]];
[self.view addSubview:nextButton];
}
-(void)pushNext {
[self.navigationController pushViewController:[[[SecondViewController alloc] init] autorelease] animated:YES];
}
@end
#import <UIKit/UIKit.h>
#import "AbstractViewController.h"
@interface SecondViewController : AbstractViewController
@end
#import "SecondViewController.h"
#import "ThirdViewController.h"
@implementation SecondViewController
-(void)loadView {
[super loadView];
UIView *previousButton = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 25, 25)] autorelease];
previousButton.backgroundColor = [UIColor orangeColor];
[previousButton addGestureRecognizer:[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popBack)] autorelease]];
[self.view addSubview:previousButton];
UIView *nextButton = [[[UIView alloc] initWithFrame:CGRectMake(10, 40, 25, 25)] autorelease];
nextButton.backgroundColor = [UIColor blueColor];
[nextButton addGestureRecognizer:[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushNext)] autorelease]];
[self.view addSubview:nextButton];
}
-(void)pushNext {
[self.navigationController pushViewController:[[[ThirdViewController alloc] init] autorelease] animated:YES];
}
-(void)popBack {
[self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
#import <UIKit/UIKit.h>
#import "AbstractViewController.h"
@interface ThirdViewController : AbstractViewController
@end
#import "ThirdViewController.h"
@implementation ThirdViewController
-(void)loadView {
[super loadView];
UIView *previousButton = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 25, 25)] autorelease];
previousButton.backgroundColor = [UIColor blueColor];
[previousButton addGestureRecognizer:[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popBack)] autorelease]];
[self.view addSubview:previousButton];
}
-(void)popBack {
[self.navigationController popViewControllerAnimated:YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment