2

以下代码有问题。

1.) 我想要达到的目标;- 在 iOS 的 AppDelegate 中显示全局背景图像或颜色

2.) 发生了什么;- 显示的图像或颜色表明代码正常工作,因为没有发生错误或警告。

3.) 有什么问题;- 背景颜色或图像几乎占据了整个屏幕,就像它是最顶层一样,因此我看不到任何元素,即 uitext、按钮等。只有背景图像..很好,因为它的工作很糟糕,因为......用户可以使用应用程序!

4.) 我做了什么;- 下面是我一直在使用的 appdelegate 中的代码片段。我知道它在每个 UIViewController 中都可以正常工作,我正在尝试重构它,所以我只在一个地方拥有它。不是200!!

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{   
    //Set the background image
    if ( IDIOM == IPAD )
    {
        self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];

    }
    else
    {
        //Add gradient background
        CAGradientLayer *bgLayer = [BackgroundLayer yellowGradient];
        bgLayer.frame = self.window.bounds;
        [self.window.layer insertSublayer:bgLayer atIndex:0];

    }

    //This is added so if in-app purchasing is used and the users connections fails in the middle of the transaction it will finalise the payment so it will download or give access to the purchase.
    //[ReadingsIAPHelper sharedInstance];

    return YES;
}

有任何想法吗?

问候,杰里米

4

1 回答 1

0

我解决了与常见包含文件中的 UIViewController 类别相同的问题。所以每个 UIviewController 在它的 init 函数中都会调用 [self setMyColor]。

这是我的代码:

@interface ColorViewController : UIViewController
    - (void) setMyColor;
@end
于 2014-01-29T10:06:33.010 回答