Swift-如何写share safari camera
来源:互联网 发布:软件缺陷的生命周期 编辑:程序博客网 时间:2024/06/08 16:44
下面是实现 Share /Safari /Camera 过程
import UIKit
import SafariServices
import MessageUI
class ViewController:UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate, MFMailComposeViewControllerDelegate {
@IBOutlet weakvar imageView: UIImageView!
@IBOutlet weakvar SharePressed: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func SharePressed(_ sender:UIButton) {
guard let image =imageView.imageelse { return }
let activityController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
activityController.popoverPresentationController?.sourceView = sender
present(activityController, animated: true, completion: nil)
}
@IBAction func SafariPressed(_ sender:UIButton) {
if let url =URL(string: "http://www.sample.net") {
let safariViewController = SFSafariViewController(url: url)
present(safariViewController,animated:true, completion: nil)
}
}
@IBAction func CameraPressed(_ sender:UIButton) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
let alertController = UIAlertController(title: "Choice a photo", message:nil, preferredStyle: .actionSheet)
//ipad使用,不加ipad上会崩溃
if let popoverController = alertController.popoverPresentationController {
popoverController.sourceView = sender
popoverController.sourceRect = sender.bounds
}
//add cancel action
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler:nil)
alertController.addAction(cancelAction)
//add camera action
ifUIImagePickerController.isSourceTypeAvailable(.camera) {
let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: { actionin
imagePicker.sourceType = .camera
self.present(imagePicker, animated:true, completion: nil) })
alertController.addAction(cameraAction)
}
//add photo library action
ifUIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
let photolibraryAction = UIAlertAction(title: "Photo Library", style: .default, handler: { actionin
imagePicker.sourceType = .photoLibrary
self.present(imagePicker,animated:true, completion: nil) })
alertController.addAction(photolibraryAction)
}
//add all choices
present(alertController, animated: true, completion: nil)
// //image handler
// func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// if let selectedImage =
// info[UIImagePickerControllerOriginalImage] as? UIImage {
// imageView.image = selectedImage
// dismiss(animated: true,completion: nil)
// }
// }
}
//image handler
func imagePickerController(_ picker:UIImagePickerController, didFinishPickingMediaWithInfo info: [String :Any]) {
if let selectedImage =
info[UIImagePickerControllerOriginalImage]as? UIImage {
imageView.image = selectedImage
dismiss(animated: true,completion: nil)
}
}
@IBAction func EmailPressed(_ sender:UIButton) {
if !MFMailComposeViewController.canSendMail() {
print("Can not send mail!")
return
}
// optional public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
- Swift-如何写share safari camera
- swift中如何写π
- 在swift如何写正则匹配
- Swift:在Safari中打开App
- 自己动手写一个Camera
- 自己动手写一个Camera
- Safari浏览器如何读取innerHTML
- Safari如何查看网页源代码
- cp -fr Camera /mnt/hgfs/share/cp: cannot create symbolic link '/mnt/hgfs/share/Camera/lib/arm64/libr
- safari
- iOS 8 Share Extension Safari URL Example(在iOS中分享url的例子)
- share
- share
- share
- share
- 如何判断Camera是否为UVC Camera
- 如何利用safari获取手机的UDID
- 如何禁止 iPhone Safari 视频自动全屏?
- Mysql01_基本类型与建表的sql
- C++并发编程学习——3.在线程间共享数据
- Linux 常用命令
- ubuntu 16.04安装cpu版本tensorflow
- thymeleaf模板引擎之基本语法
- Swift-如何写share safari camera
- 理解 module.exports和node.js的exports
- Python 练习实例4
- JavaScript中使用html音频对象audio
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- .deb软件包的安装和软件的卸载
- 对话框Diglog的应用
- JUnit笔记--JUnit中的断言
- C#面试知识点小结