2012-07-30 90 views
0

我相信我有確定,如果我的申請已被打開之前一成不變的代碼:重疊視圖第一次打開

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
BOOL didFirstLaunch = [defaults boolForKey:@"DidFirstLaunch"]; 
if (!didFirstLaunch) { 
    [defaults setBool: YES forKey:@"DidFirstLaunch"]; 

    //Code for assembling overlay view 
} 

我把這個代碼在didFinishLaunchingWithOptions方法。

我希望透明疊加視圖僅覆蓋3/4的iPhone屏幕並略微透明,因此您仍然可以看到我的應用程序的主要頁面 - 它上面會有幾張圖片和文字(基本上是一個簡單的教程)。 我如何着手創建這種性質的簡單視圖?

+0

你的問題是什麼?你告訴我們你在做什麼,沒有更多。 – 2012-07-30 23:55:32

回答

4

你應該把你的代碼didFinishLaunchingWithOptions方法:

BOOL didFirstLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"DidFirstLaunch"]; 

if (!didFirstLaunch) { 

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"DidFirstLaunch"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 

    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, window.frame.size.width, window.frame.size.height)]; 
    //add some stuff to your transparent view. Example background color 
    [v setBackgroundColor:[UIColor orangeColor]]; 

    // Finally set the alpha value 
    [v setAlpha:0.3]; 
    [window addSubview:v]; 

} 

希望它能幫助。 ;)

0

有關問題的透明覆蓋部分...

我認爲這是最簡單的創建一個覆蓋整個屏幕子視圖,然後減去離開你想要的部分。下面是一些銀行代碼,可以幫助:

// Create a view filling the screen. 
let overlay = UIView(frame: CGRectMake(0, 0, 
    UIScreen.mainScreen().bounds.width, 
    UIScreen.mainScreen().bounds.height)) 

// Set a semi-transparent, black background. 
overlay.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.85) 

// Create the initial layer from the view bounds. 
let maskLayer = CAShapeLayer() 
maskLayer.frame = overlay.bounds 
maskLayer.fillColor = UIColor.blackColor().CGColor 

// Create the frame for the portion that you want to remove. 
// You could get this from a container view that holds all of 
// the subviews that you want to see behind the overlay. 
let rect = CGRectMake(50, 50, 100, 100) 

// Create the path. 
let path = UIBezierPath(rect: overlay.bounds) 
maskLayer.fillRule = kCAFillRuleEvenOdd 

// Append the rectangle to the path so that it is subtracted. 
path.appendPath(UIBezierPath(rect: rect)) 
maskLayer.path = path.CGPath 

// Set the mask of the view. 
overlay.layer.mask = maskLayer 

// Add the view so it is visible. 
self.view.addSubview(overlay) 

這裏是上面的代碼是什麼樣的行動:

enter image description here

我添加了一個library到的CocoaPods,允許您創建半透明覆蓋帶有矩形/圓形孔,允許用戶與覆蓋層後面的視圖進行交互。我用它來爲我們的應用程序創建一個本教程:

Tutorial using the TAOverlayView

庫被稱爲TAOverlayView,並使用Apache 2.0的開源。