2016-10-29 97 views
0

我曾嘗試通過google/youtube等搜索實現菜單的方式,但仍無法找到實現此目的的方法。Facebook圖片彈出菜單

我該如何實現這種彈出菜單? : - enter image description here

任何建議將不勝感激。

+1

這與UIAlertControllerStyleActionSheet https://developer.apple的風格本土UIAlertController。 com/reference/uikit/uialertcontroller – Jota

+0

@Jota非常感謝您指出正確的方向。祝你今天愉快! – aznelite89

回答

3

您可以使用此代碼來實現這一點。這與斯威夫特3和8的XCode

let actionSheet: UIAlertController = UIAlertController.init(title: "Title of the action sheet", message: "Message to display", preferredStyle: .actionSheet) 

    //Create and add the Cancel action 
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in 
     //Just dismiss the action sheet 
    } 
    actionSheet.addAction(cancelAction) 

    //Create and add first option action 
    let savePictureAction: UIAlertAction = UIAlertAction(title: "Using Camera", style: .default) { action -> Void in 
     // Write Save Method Here 
    } 
    actionSheet.addAction(savePictureAction) 

    //Create and add a second option action 
    let sendInMessenger: UIAlertAction = UIAlertAction(title: "Choose Existing Photo", style: .default) { action -> Void in 
     // Write your code to Send In Messenger Here 
    } 
    actionSheet.addAction(sendInMessanger) 

    //Create and add a third option action 
    let dontLikePhoto: UIAlertAction = UIAlertAction(title: "Choose Existing Photo", style: .default) { action -> Void in 
     // Write your code if you Don't like photo Here 
    } 
    actionSheet.addAction(dontLikePhoto) 

    //Create and add a third option action 
    let trunOnNotification: UIAlertAction = UIAlertAction(title: "Choose Existing Photo", style: .default) { action -> Void in 
     // Write your code Turn on Notifications Here 
    } 
    actionSheet.addAction(trunOnNotification) 

    //We need to provide a popover sourceView when using it on iPad 
    actionSheet.popoverPresentationController?.sourceView = sender as? UIView 

    //Present the AlertController 
    self.present(actionSheet, animated: true, completion: nil) 

工作請注意,這種方法可從iOS版9