2009.02.26
02:35
author: taikiken
0件のコメント
iPhone デベロッパーズ クックブック レシピ 2-2。
コードをヘッダー、ソースと分けてみた。
プロジェクト名:RotateView
.xib, .nib ファイルを削除。
RotateViewAppDelegate.h
#import <UIKit/UIKit.h>
@class RotateViewViewController;
@interface RotateViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RotateViewViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RotateViewViewController *viewController;
@end |
#import <UIKit/UIKit.h>
@class RotateViewViewController;
@interface RotateViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RotateViewViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RotateViewViewController *viewController;
@end
RotateViewAppDelegate.m
#import "RotateViewAppDelegate.h"
#import "RotateViewViewController.h"
@implementation RotateViewAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
viewController = [[RotateViewViewController alloc] init];
[window addSubview:[ viewController view]];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end |
#import "RotateViewAppDelegate.h"
#import "RotateViewViewController.h"
@implementation RotateViewAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
viewController = [[RotateViewViewController alloc] init];
[window addSubview:[ viewController view]];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
RotateViewViewController.h
#import <UIKit/UIKit.h>
@interface RotateViewViewController : UIViewController {
}
@end |
#import <UIKit/UIKit.h>
@interface RotateViewViewController : UIViewController {
}
@end
RotateViewViewController.m
#import "RotateViewViewController.h"
@implementation RotateViewViewController
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
CGRect apprect;
apprect.origin = CGPointMake(0.0f, 0.0f);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
apprect.size = CGSizeMake(480.0f, 300.0f);
else
apprect.size = CGSizeMake(320.0f, 460.0f);
// Iterate through the subviews and inset each item
float offset = 32.0f;
for (UIView *subview in [self.view subviews])
{
CGRect frame = CGRectInset(apprect, offset, offset);
[subview setFrame:frame];
offset += 32.0f;
}
}
- (void)loadView
{
// Create the main view
UIView *contentView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
// Get the view bounds as our starting point
CGRect apprect = [contentView bounds];
// Add each inset subview
UIView *subview = [[UIView alloc] initWithFrame:CGRectInset(apprect, 32.0f, 32.0f)];
subview.backgroundColor = [UIColor lightGrayColor];
[contentView addSubview:subview];
[subview release];
subview = [[UIView alloc] initWithFrame:CGRectInset(apprect, 64.0f, 64.0f)];
subview.backgroundColor = [UIColor darkGrayColor];
[contentView addSubview:subview];
[subview release];
subview = [[UIView alloc] initWithFrame:CGRectInset(apprect, 96.0f, 96.0f)];
subview.backgroundColor = [UIColor blackColor];
[contentView addSubview:subview];
[subview release];
}
// Allow the view to respond to all iPhone Orientation changes
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end |
#import "RotateViewViewController.h"
@implementation RotateViewViewController
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
CGRect apprect;
apprect.origin = CGPointMake(0.0f, 0.0f);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
apprect.size = CGSizeMake(480.0f, 300.0f);
else
apprect.size = CGSizeMake(320.0f, 460.0f);
// Iterate through the subviews and inset each item
float offset = 32.0f;
for (UIView *subview in [self.view subviews])
{
CGRect frame = CGRectInset(apprect, offset, offset);
[subview setFrame:frame];
offset += 32.0f;
}
}
- (void)loadView
{
// Create the main view
UIView *contentView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
// Get the view bounds as our starting point
CGRect apprect = [contentView bounds];
// Add each inset subview
UIView *subview = [[UIView alloc] initWithFrame:CGRectInset(apprect, 32.0f, 32.0f)];
subview.backgroundColor = [UIColor lightGrayColor];
[contentView addSubview:subview];
[subview release];
subview = [[UIView alloc] initWithFrame:CGRectInset(apprect, 64.0f, 64.0f)];
subview.backgroundColor = [UIColor darkGrayColor];
[contentView addSubview:subview];
[subview release];
subview = [[UIView alloc] initWithFrame:CGRectInset(apprect, 96.0f, 96.0f)];
subview.backgroundColor = [UIColor blackColor];
[contentView addSubview:subview];
[subview release];
}
// Allow the view to respond to all iPhone Orientation changes
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"RotateViewAppDelegate");
[pool release];
return retVal;
} |
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"RotateViewAppDelegate");
[pool release];
return retVal;
}
分からないことだらけ。
#import
は PHP の require_once()
と同じように働くらしい。
SDKの説明に「2回以上インクルードしない」と書いてあった。