TestTransition.app : Select all

/* TestTransition.h */ #import <CoreFoundation/CoreFoundation.h> #import <UIKit/UIKit.h> #import <UIKit/UINavigationBar.h> #import <UIKit/UINavigationItem.h> #import <UIKit/UITransitionView.h> #import <UIKit/UITextView.h> #define MAX_PAGES 10 @interface MainView : UIView { UINavigationBar *navBar; /* Our navigation bar */ UINavigationItem *navItem; /* Navigation bar title */ UITransitionView *transView; /* Our transition */ int pageNum; /* Current page number */ /* Some pages to scroll through */ UITextView *textPage[MAX_PAGES]; } - (id)initWithFrame:(CGRect)frame; - (void)dealloc; - (UINavigationBar *)createNavBar:(CGRect)rect; - (void)setNavBar; - (void)navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button; - (void)flipTo:(int)page; @end @interface TestTransition : UIApplication { UIWindow *window; MainView *mainView; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification; @end /* TestTransition.m */ #import "TestTransition.h" @implementation TestTransition - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { window = [ [ UIWindow alloc ] initWithContentRect: [ UIHardware fullScreenApplicationContentRect ] ]; CGRect rect = [ UIHardware fullScreenApplicationContentRect ]; rect.origin.x = rect.origin.y = 0.0f; mainView = [ [ MainView alloc ] initWithFrame: rect ]; [ window setContentView: mainView ]; [ window orderFront: self ]; [ window makeKey: self ]; [ window _setHidden: NO ]; } @end @implementation MainView - (id)initWithFrame:(CGRect)rect { if ((self == [ super initWithFrame: rect ]) != nil) { CGRect viewRect; int i; /* Create a new view port below the navigation bar */ viewRect = CGRectMake(rect.origin.x, rect.origin.y + 48.0, rect.size.width, rect.size.height - 48.0); /* Set our start page */ pageNum = MAX_PAGES / 2; /* Create ten UITextView objects as pages in our book */ for(i = 0; i < MAX_PAGES ; i++) { textPage = [ [ UITextView alloc ] initWithFrame: rect ]; [ textPage setText: [ [ NSString alloc ] initWithFormat: @"Some text for page %d", i+1 ] ]; } /* Create a navigation bar with 'Prev' and 'Next' buttons */ navBar = [ self createNavBar: rect ]; [ self setNavBar ]; [ self addSubview: navBar ]; /* Create our transition view */ transView = [ [ UITransitionView alloc ] initWithFrame: viewRect ]; [ self addSubview: transView ]; /* Transition to the first page */ [ self flipTo: pageNum ]; } return self; } - (void)dealloc { [ navBar release ]; [ navItem release ]; [ self dealloc ]; [ super dealloc ]; } - (UINavigationBar *)createNavBar:(CGRect)rect { UINavigationBar *newNav = [ [UINavigationBar alloc] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, 48.0) ]; [ newNav setDelegate: self ]; [ newNav enableAnimation ]; /* Add our title */ navItem = [ [UINavigationItem alloc] initWithTitle:@"Test Transition" ]; [ newNav pushNavigationItem: navItem ]; [ newNav showLeftButton:@"Prev" withStyle: 0 rightButton:@"Next" withStyle: 0 ]; return newNav; } - (void)setNavBar { /* Enable or disable our page buttons */ if (pageNum == 1) [ navBar setButton: 1 enabled: NO ]; else [ navBar setButton: 1 enabled: YES ]; if (pageNum == MAX_PAGES) [ navBar setButton: 0 enabled: NO ]; else [ navBar setButton: 0 enabled: YES ]; } - (void)navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button { /* Next Page */ if (button == 0) { [ self flipTo: pageNum+1 ]; } /* Prev Page */ else { [ self flipTo: pageNum-1 ]; } } - (void)flipTo:(int)page { int transitionNum; /* What transition number should be used? */ if (page < pageNum) transitionNum = 2; else if (page > pageNum) transitionNum = 1; else transitionNum = 0; [ transView transition: transitionNum fromView: textPage[pageNum-1] toView: textPage[page-1] ]; pageNum = page; [ self setNavBar ]; } @end