【发布时间】:2013-06-19 19:55:57
【问题描述】:
以下代码有问题。
1.) 我想要实现的目标; - 在 iOS 的 AppDelegate 中显示全局背景图像或颜色
2.) 发生了什么; - 显示的图像或颜色表明代码工作正常,没有出现错误或警告。
3.) 问题是什么; - 背景颜色或图像几乎占据了整个屏幕,就像它是最顶层一样,因此我看不到任何元素,即 uitext、按钮等。只有背景图像......很好,因为它的工作很糟糕,因为......用户可以使用应用程序!
4.) 我做了什么; - 下面是我一直在使用的 appdelegate 中的代码 sn-p。我知道它在每个 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;
}
有什么想法吗?
问候, 杰里米
【问题讨论】:
-
有没有试过把子层放到后面?
-
对不起...还在学习 objC....怎么做呢?
-
[self.window.layer sendSublayerToBack:bgLayer]; -
嗨,Wain,没用。它无法识别“sendSublayerToBack”属性。我找到了一些示例,您可以将整个字符串设置为负值,即 [self.window.layer insertSublayer:bgLayer atIndex:-1];但当然这也不起作用....
-
对不起,只是为了澄清上面的 I 标记正在运行第二个语句。 CAGradienLayer 不是图像。
标签: ios image background global