Facebook图片弹出菜单

时间:2016-10-29 03:36:06

标签: ios swift xcode

我曾尝试通过google / youtube等搜索实现菜单的方式,但仍无法找到实现此目的的方法。

我怎样才能实现这样的弹出菜单? : - enter image description here

任何建议都会非常感激。

1 个答案:

答案 0 :(得分:3)

您可以使用此代码来实现此目的。这适用于Swift 3和XCode 8。

    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获得。