關鍵點:
1.在info.plistj城去掉Main nib file base name,這樣啓動時就不要求有nib
2.修改main.m
int retVal = UIApplicationMain(argc, argv, nil, @"app delegate名稱");
這裏必須指定app delegate,不能寫nil了。
3.在app delegate裏創建window和view
CGRect screenBounds = [ [ UIScreen mainScreen ] applicationFrame ];
CGRect windowBounds = screenBounds;
windowBounds.origin.y = 0.0;
self.window = [ [ [ UIWindow alloc ] initWithFrame: screenBounds ]
autorelease
];
mainview = [ [ MainView alloc ] initWithFrame: windowBounds ];
[window addSubview:mainview];
[window makeKeyAndVisible];
基本上類似這個,當然mainview和window這兩個成員要自己定義
UIWindow *window;
MainView *mainview;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MainView *mainview;
MainView是一個自定義UIView,繼承下來的,作爲唯一界面。
4.創建自己的UIView。
@interface MainView : UIView {
//CGImageRef image;
UIImage *image;
}
@implementation MainView
- (id)initWithFrame:(CGRect)frame {
NSLog(@"init ");
self = [super initWithFrame:frame];
if(self != nil)
{
// Initialization code
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"bg.jpg" ofType:nil];
UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
image=img;
NSLog(@"init image");
self.backgroundColor = [UIColor blackColor];
self.opaque = YES;
self.clearsContextBeforeDrawing = YES;
}
return self;
}
- (void)drawRect:(CGRect)rect {
[image drawAtPoint:CGPointMake(0, 0)];
}
這樣就畫了一張jpg圖片,當然圖片必須放到project裏。
view controller就忽略掉了,因爲只有一個view,就不用這個了。
下一步就搞清旋轉屏幕,永遠是橫屏顯示。