2012-02-23 62 views
1

我一直在寻找一种方法来改变水平翻转动画中的黑色背景色,但到目前为止,我没有任何技巧。翻转水平动画时的背景颜色

This is what it looks like right now

我真的很感激,如果有人可以帮助我!这里是我一直在使用动画代码:

ViewController.h:

-(IBAction)howitworksbutton:(id)sender; 

ViewController.m:

-(IBAction)howitworksbutton:(id)sender 
{ 
     howitworks *secondview = [[howitworks alloc] initWithNibName:nil bundle:nil]; 
     secondview.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:secondview animated:YES]; 
} 

我还创建了一个新的UIViewController被称为'howitworks'的子类。

问候,伊瓦

回答

5

尝试,并设置您的应用程序代理的窗口对象的背景色:

YourAppDelegate *delegate =[[UIApplication sharedApplication] delegate]; 
[[delegate window] setBackgroundColor:[UIColor redColor]]; 

我认为这是主要的背景色,坐在后面的所有的应用程序的意见。

+0

感谢您的答复,斯利!我应该把这段代码放在AppDelegate.m文件中吗?然后创建一个applicationDidFinishLaunching? – 2012-02-23 19:50:48

+1

你可以进入你的应用代理代码并将其设置为 – Slee 2012-02-24 19:31:13

0
[self.view setBackgroundColor:[UIColor whiteColor]]; 
+0

谢谢Javy!我想我已经试过了,但也许我把它放在了错误的地方。我应该把这个放在哪里?我是Xcode的新手,很抱歉所有这些愚蠢的问题。 – 2012-02-23 19:55:24

+0

你可以把它放在viewDidLoad中,它应该没问题。我还没有看到其他代码,所以Slee的答案可能会(或可能不会)更合适。 – TigerCoding 2012-02-24 08:49:51

+0

不幸的是,代码没有工作。我已经尝试添加Slee的代码,但是这也不起作用。也许这是不可能的?再次感谢Javy的帮助! – 2012-02-24 19:41:31

0

斯威夫特3:

打开文件AppDelegate.swift

内部功能didFinishLaunchingWithOptions

添加window?.backgroundColor = hexStringToUIColor("#EEEEEE")


更多的东西:

hexStringToUIColor是一个辅助方法,你可以用你的方式来创建UIColor

func hexStringToUIColor (_ hex:String) -> UIColor { 
    var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased() 

    if (cString.hasPrefix("#")) { 
     cString.remove(at: cString.startIndex) 
    } 

    if ((cString.characters.count) != 6) { 
     return UIColor.gray 
    } 

    var rgbValue:UInt32 = 0 
    Scanner(string: cString).scanHexInt32(&rgbValue) 

    return UIColor(
     red: CGFloat((rgbValue & 0xFF0000) >> 16)/255.0, 
     green: CGFloat((rgbValue & 0x00FF00) >> 8)/255.0, 
     blue: CGFloat(rgbValue & 0x0000FF)/255.0, 
     alpha: CGFloat(1.0) 
    ) 
}