2016-04-27 32 views
0

所以我已經使用這個代碼截圖特定區域(表格單元格),這是在屏幕上可見:程序上的截圖

UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, false, 0.0) 
inputView.layer.renderInContext(UIGraphicsGetCurrentContext()!) 
let image = UIGraphicsGetImageFromCurrentImageContext() as UIImage 
UIGraphicsEndImageContext() 
let cellSnapshot : UIView = UIImageView(image: image) 

不過,現在我的目標是更多的東西複雜:

  1. 首先,編程截圖整個屏幕
  2. 呈現給用戶,主要致盲他們一會兒
  3. 那我還可以將一些東西像

棘手的部分...雖然圖像仍然隱藏新的設置,我想截圖/捕獲的觀點,即排列的圖像背後周圍(包括圖像下的每個單一視圖) 。

爲什麼要這樣做?風險投資並沒有改變,但我將滑入第二張圖片,看起來這個新的安排是一個新的屏幕。

這可能嗎?

+0

這似乎是可能的,但比創建一個新的ViewController更麻煩。 –

回答

0

所以這裏的代碼拍攝任何視圖的快照!只需粘貼此功能並將其傳遞給您想要捕捉的視圖即可!

let pictureOfView = snapshotOfView(passAViewHere) 

func snapshotOfView (inputView: UIView) -> UIView { 
    UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, false, 0.0) 
    inputView.layer.renderInContext(UIGraphicsGetCurrentContext()!) 
    let image = UIGraphicsGetImageFromCurrentImageContext() as UIImage 
    UIGraphicsEndImageContext() 
    let cellSnapshot : UIView = UIImageView(image: image) 
    cellSnapshot.layer.masksToBounds = false 

    return cellSnapshot 
}