首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何分别获取基于摄像头和基于媒体的图像/视频,以在iOS设备的集合视图中显示

如何分别获取基于摄像头和基于媒体的图像/视频,以在iOS设备的集合视图中显示
EN

Stack Overflow用户
提问于 2016-03-01 14:44:05
回答 1查看 132关注 0票数 0

我正在开发一个聊天应用程序。在我的应用程序中,当我点击attachement按钮时,应该会出现两个选项。

1)设备摄像头采集到的图像/视频(当时没有采集到图像。获取存储在设备中的摄像头拍摄的图像)

2)从网络或其他媒体下载的图像/视频

有没有办法根据上面给定的条件,最好使用assets库来获取图像/视频

EN

回答 1

Stack Overflow用户

发布于 2016-03-01 15:08:49

代码语言:javascript
复制
class YourController :  UIViewController,UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate,UIPopoverPresentationControllerDelegate
{    

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    func takePhotoByGalleryOrCamera(){

        //MAark Take picture from gallery and camera 
        //image picker controller to use take image 
        // uialert controller to make action

        let imageController = UIImagePickerController()
        imageController.editing = false
        imageController.delegate = self;

        let alert = UIAlertController(title: "", message: "Profile Image Selctor", preferredStyle: UIAlertControllerStyle.ActionSheet)


        let libButton = UIAlertAction(title: "Select photo from library", style: UIAlertActionStyle.Default) { (alert) -> Void in
            imageController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
            self.presentViewController(imageController, animated: true, completion: nil)
        }


        if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
            let cameraButton = UIAlertAction(title: "Take a picture", style: UIAlertActionStyle.Default) { (alert) -> Void in
                print("Take Photo")
                imageController.sourceType = UIImagePickerControllerSourceType.Camera
                self.presentViewController(imageController, animated: true, completion: nil)

            }
            alert.addAction(cameraButton)
        } else {
            print("Camera not available")

        }
        let cancelButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (alert) -> Void in
            print("Cancel Pressed")
        }

        alert.addAction(libButton)
        alert.addAction(cancelButton)

        if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad {

            alert.modalPresentationStyle = UIModalPresentationStyle.Popover;
            //        alert.transitioningDelegate = self;
            alert.popoverPresentationController!.sourceView = self.view;
            alert.popoverPresentationController!.sourceRect = CGRectMake(0, SizeUtil.screenHeight(), SizeUtil.screenWidth(), SizeUtil.screenHeight()*0.4)
            alert.popoverPresentationController!.delegate = self;

            self.presentViewController(alert, animated: true, completion: nil)
        } else {
           self.presentViewController(alert, animated: true, completion: nil)
        }



    }

    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {

        return UIModalPresentationStyle.Popover
    }


    //image picker Delegate
    func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
        self.dismissViewControllerAnimated(true, completion: nil)

        let header = profileTableView.headerViewForSection(0) as! ProfileHeaderView
        header.btnImage.setImage(image, forState: UIControlState.Normal)
        _userProfileImage = image

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35716330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档