我正在玩一个非常小的单视图应用程序,以了解视图是如何工作的。我对 iOS 开发非常陌生。我正在使用我放在一起的图像作为我唯一视图的背景。运行应用程序时,我的背景是巨大的。就好像它被放大或缩放一样。我正在关注 Big Nerd Ranch 视图教程,因此我正在使用 UIView 的一个子类,称为 HypnosisView。这是暂时的。值得一提的是,我尝试用作背景的图像正好是 640 x 1136 像素。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
CGRect viewFrame = CGRectMake(0, 0, 640, 1136);
HypnosisView *view = [[HypnosisView alloc] initWithFrame:viewFrame];
[view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"BG.png"]]];
[[self window] addSubview:view];
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
return YES;
}
更新了尝试使用 0、0、320、568 帧实现 UIImageView 的代码。我还创建了一个 320 大小的背景,然后是一个全尺寸的背景,并用正确的标题命名它们。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
CGRect viewFrame = CGRectMake(0, 0, 320, 568);
UIImage *background = [UIImage imageNamed:@"background@2x.png"];
UIImageView *backgroundView = [[[UIImageView alloc] initWithImage:background] initWithFrame:viewFrame];
[[self window] addSubview:backgroundView];
[[self window] sendSubviewToBack:backgroundView];
self.window.backgroundColor = [UIColor clearColor];
[self.window makeKeyAndVisible];
return YES;
}