有關問題的透明覆蓋部分...
我認爲這是最簡單的創建一個覆蓋整個屏幕子視圖,然後減去離開你想要的部分。下面是一些銀行代碼,可以幫助:
// 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)
這裏是上面的代碼是什麼樣的行動:
我添加了一個library到的CocoaPods,允許您創建半透明覆蓋帶有矩形/圓形孔,允許用戶與覆蓋層後面的視圖進行交互。我用它來爲我們的應用程序創建一個本教程:
庫被稱爲TAOverlayView,並使用Apache 2.0的開源。
你的問題是什麼?你告訴我們你在做什麼,沒有更多。 – 2012-07-30 23:55:32