2015-08-26 90 views
1

我已經完成了沒有導航欄的全屏截圖的編碼,但我也不想要「激勵我」按鈕。裁剪截圖並分享?

enter image description here

另外,如果有人知道如何分享作物截圖給Facebook?

下面是截圖代碼:

UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size,false,0); 
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true) 
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

回答

1

確保激勵我按鈕是不是你正在服用的截圖上視圖的層次結構內。將它移動到單獨的視圖上,然後使用您已有的相同代碼。這將完全符合你的要求。

或者,如果你要裁剪的整個照片,你可以使用下面的,請更換heightOfButton值,以滿足:

var heightOfButton: CGFloat = 100 
var size = UIScreen.mainScreen().bounds.size 
size.height -= heightOfButton 
UIGraphicsBeginImageContextWithOptions(size,false,0); 
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true) 
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 
+0

廣東話,我們只寫了代碼,並裁剪圖像並將其保存到圖片庫 – motivation1

+0

89感謝已經更新了我的答案 – Swinny89

+0

@swimnny您answer.Its偉大的,但寬度不來好,所以如何改變寬度 – motivation1

1

就隱藏UIButton你拍攝快照前和取消隱藏它,你走之後截圖。

func screenshot() { 
    // Hide button 
    myButton.alpha = 0.0 

    // Take screenshot 
    UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size,false,0) 
    self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true) 
    var image:UIImage = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 

    // Unhide button 
    myButton.alpha = 1.0 
} 

要將圖片分享至Facebook,您可以使用SLComposeViewController

在附註中,您不需要在Swift中的每行末尾使用;