私は iOS 開発は初めてですが、最近、大規模な短期集中コース (iOS プログラミングの BNR ガイド) を受講しました。ビューをアプリにモーダルに追加する作業を行っています。現在、View Controller を持っていないため、AppDelegate のapplication:didFinishLaunchingWithOptions
メソッドは次のようになります。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MyUIView *map = [[MapSurface alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//this one does not work: MyUIView *map = [[MapSurface alloc] initWithFrame:CGRectMake(0, 0, 256, 256)];
[map setBackgroundColor:[UIColor grayColor]];
[[self window] addSubview:map];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
ビューが読み込まれた後、サブビューを追加するための呼び出しを行いますが、を使用してフレーム サイズを設定できませんCGRectMake
。画面に表示されません。私が見つけた唯一のことは、画面サイズを使用することですが、これは私が望むものではありません。このサブビューを追加するコードは次のとおりです。
UIImage *image = [[UIImage alloc] initWithCGImage:img];//img is a CGImageRef
UIImageView *view = [[UIImageView alloc] initWithImage:image];
CGRect b = CGRectMake(0, 0, 256, 256);
//[view setFrame:b];//nothing shows on screen
//[view setBounds:b];//nothing shows on screen
//[view setBounds:[[UIScreen mainScreen] bounds]];//shows the tan area in the graphic below
[view setFrame:[[UIScreen mainScreen] bounds]];//fills the screen
[map addSubView:view];
CGImageRelease(img);