为整个应用设置绝对背景

Set Absolute Background for Entire App

我想为我的应用放置一个无论如何都不会移动的绝对背景图片。

我希望看起来好像我的 segues 只是将 destinationViewController 的视图移动到这个背景上,就好像它是一页一样。

我看过这个答案,set background image for entire iPhone / iPad app,但是如前所述,colorWithPatternImage 会吞噬记忆。

我想要 Objective-C 和 Swift 中的答案。

谢谢

最简单的方法是将 UIImageView 添加到根 window 并确保所有其他视图都具有透明背景;

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    let window=self.window!

    let backgroundView=UIImageView(frame: window.frame)

    backgroundView.image=UIImage(named: "Background.JPG")!

    window.addSubview(backgroundView)

    return true
}

或在Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

    UIWindow *window=application.windows.firstObject;
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:window.frame];

    imageView.image=[UIImage imageNamed:@"Background.jpg"];

    [window addSubview:imageView];
    return YES;
}