ExtJS-UI组件-ActionSheet

Posted 重庆熊猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ExtJS-UI组件-ActionSheet相关的知识,希望对你有一定的参考价值。

更新记录
2023年3月8日 发布。

ExtJS教程汇总:https://www.cnblogs.com/cqpanda/p/16328016.html
转载请注明出处:https://www.cnblogs.com/cqpanda/p/17192499.html

作用

Ext.ActionSheet are used to display a list of Ext.Button in a popup dialog.

实例

基础使用

var actionSheet = Ext.create(\'Ext.ActionSheet\', 
    items: [
        
            text: \'Delete draft\',
            ui  : \'decline\'
        ,
        
            text: \'Save draft\'
        ,
        
            text: \'Cancel\',
            ui  : \'confirm\'
        
    ]
);

Ext.Viewport.add(actionSheet);
actionSheet.show();

以 ActionSheet 样式访问图片库

【中文标题】以 ActionSheet 样式访问图片库【英文标题】:Accessing picture library in an ActionSheet style 【发布时间】:2015-07-17 14:01:33 【问题描述】:

我正在尝试在注册视图控制器中创建 profilePic。 profilePic 是 UIImageView 类型。我希望能够点击它,以便它立即以 ActionSheet 样式调出照片库。并且还有一个图像框有一个按钮来访问相机。这可能吗?

import UIKit

class SignUpViewController: UIViewController, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate 

    @IBOutlet weak var profilePic: UIImageView!


    override func viewDidLoad() 
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        // PROFILE PICTURE

        let tapGesture = UITapGestureRecognizer(target: self, action: "imageTapped:")

        profilePic.addGestureRecognizer(tapGesture)
        profilePic.userInteractionEnabled = true

    


    func imageTapped(gesture:UIGestureRecognizer) 
        if let profile1Pic = gesture.view as? UIImageView 
            print("Image Tapped")
        
    

【问题讨论】:

【参考方案1】:

试试下面的代码:

import UIKit

class SignUpViewController: UIViewController, UIImagePickerControllerDelegate 

@IBOutlet weak var profilePic: UIImageView!


override func viewDidLoad() 
  super.viewDidLoad()

  let tapGesture = UITapGestureRecognizer(target: self, action: "imageTapped:")

  profilePic.addGestureRecognizer(tapGesture)
  profilePic.userInteractionEnabled = true




func imageTapped(gesture:UIGestureRecognizer) 
  if let profile1Pic = gesture.view as? UIImageView 
      print("Image Tapped")
      showActionSheet()
  

func camera()

    var myPickerController = UIImagePickerController()
    myPickerController.delegate = self;
    myPickerController.sourceType = UIImagePickerControllerSourceType.Camera

    self.presentViewController(myPickerController, animated: true, completion: nil)



func photoLibrary()


    var myPickerController = UIImagePickerController()
    myPickerController.delegate = self;
    myPickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

    self.presentViewController(myPickerController, animated: true, completion: nil)



func showActionSheet() 
    let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)

    actionSheet.addAction(UIAlertAction(title: "Camera", style: UIAlertActionStyle.Default, handler:  (alert:UIAlertAction!) -> Void in
        self.camera()
    ))

    actionSheet.addAction(UIAlertAction(title: "Gallery", style: UIAlertActionStyle.Default, handler:  (alert:UIAlertAction!) -> Void in
        self.photoLibrary()
    ))

    actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))

    self.presentViewController(actionSheet, animated: true, completion: nil)



func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) 

    profilePic.image = info[UIImagePickerControllerOriginalImage] as? UIImage
    self.dismissViewControllerAnimated(true, completion: nil)



它在我身边工作..希望能为你做一些事情!

【讨论】:

它非常适合我。非常感谢你。我只需要添加 UINavigationControllerDelegate @MartinQ 欢迎,如果它是完美的,那么请介意投票给我的答案:) 显然,我的名声不够高。我很快就会……和我一起裸露。再次感谢您 我如何启用allowEditing模式,以便用户可以放大和缩小以将图像裁剪到理想的尺寸?例如,在上面的代码中,我在 photoLibrary 函数和相机函数以及 func imagePickerController 函数中添加了 myPickerController.allowsEditing = true ,我将 progilePic 图像操作的调用更改为 profilePic.image = info[UIImagePickerControllerEditedImage] 为? UIImage @MartinQ 我还没有尝试编辑图像。所以你可以参考this或this【参考方案2】:

我最近发布了一个 GitHub 存储库来处理这种类型的操作表。

你可以从这里下载这个课程:MSActionSheet

然后简单地写:

编辑:

● 现在支持 iPad

MSActionSheet(viewController: self, sourceView: sender).showFullActionSheet 
       sender.setImage($0, for: .normal)

【讨论】:

【参考方案3】:

MSActionSheet:是设置用户头像的最佳库。

我使用了这个库 但它在 iPad中不受支持所以我 自定义某些功能以支持 iPad 和 Display with popOverController

定制步骤以下。

    showFullActionSheet替换函数

    func showFullActionSheet(on vc : UIViewController, over btn : UIButton,handler : @escaping (_ : UIImage?) -> Void) 
        let sheet = create().addLibrary().addFrontCamera().addRearCamera().addCancelButton()
        sheet.show(on: vc,over: btn) (image : UIImage?) in
            handler(image)
        
    
    

    在函数showvc.present(MSActionSheet.sheet!, animated: true, completion: nil)之前添加代码

    if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad 
            if let presenter = MSActionSheet.sheet?.popoverPresentationController 
                presenter.sourceView = btn
                presenter.sourceRect = btn.bounds
            
        
    

    在函数handlerclientVC?.present(picker, animated: true, completion: nil)之前添加以下代码

    if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad 
            picker.modalPresentationStyle = .popover
            if let presenter = picker.popoverPresentationController 
                presenter.sourceView = sourceBtn
                presenter.sourceRect = sourceBtn!.bounds
            
        
    

    如何使用

    let msActionSheet = MSActionSheet.instance
        msActionSheet.showFullActionSheet(on: self,over: btn) (image) in
            btn.setImage(image, for: .normal)
        
        msActionSheet.tintColor(color: Constants.kColorBluish)
    

【讨论】:

请查看新版本,支持iPad【参考方案4】:

Swift 3x:

 class yourClassName:UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate 


 @IBAction func yourButtonName(_ sender: UIButton) 


        let pickerView = UIImagePickerController()
        pickerView.delegate = self
        pickerView.allowsEditing = true


        let actionSheetControllerIOS8: UIAlertController = UIAlertController(title: "Please select", message: nil, preferredStyle: .actionSheet)

        let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel)  action -> Void in
            print("Cancel") //Cancel
        
        actionSheetControllerIOS8.addAction(cancelActionButton)

        let saveActionButton: UIAlertAction = UIAlertAction(title: "Take Photo", style: .default)  action -> Void in

            print("Take Photo") //Will open Camera
            if UIImagePickerController.isSourceTypeAvailable(.camera) 

                pickerView.sourceType = .camera
                self.present(pickerView, animated: true, completion:  _ in )
            

        
        actionSheetControllerIOS8.addAction(saveActionButton)

        let deleteActionButton: UIAlertAction = UIAlertAction(title: "Camera Roll", style: .default)  action -> Void in

            print("Camera Roll") //Will open Gallery

            pickerView.sourceType = .photoLibrary
            self.present(pickerView, animated: true, completion:  _ in )

        
        actionSheetControllerIOS8.addAction(deleteActionButton)

        let deleteActionButton2: UIAlertAction = UIAlertAction(title: "Import from Facebook", style: .default)  action -> Void in
            print("Import from Facebook")
        

        actionSheetControllerIOS8.addAction(deleteActionButton2)
        self.present(actionSheetControllerIOS8, animated: true, completion: nil)

    

// MARK: - UIImagePickerControllerDelegate Methods

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) 

//print(info)
if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage 

    //print(pickedImage)

    yourImageView.contentMode = .scaleAspectFit
    yourImageView.image = pickedImage


dismiss(animated: true, completion: nil)



【讨论】:

以上是关于ExtJS-UI组件-ActionSheet的主要内容,如果未能解决你的问题,请参考以下文章

返回 UIAlertControllerStyle.ActionSheet 中选择的动作

模仿微信的Actionsheet

UIAlertController(ActionSheet)-无法同时满足约束[重复]

Cordova ActionSheet 插件

ionic-Javascript:ionic 上拉菜单(ActionSheet)

iOS 自定义Actionsheet