Commit b3454de7 authored by pete谢兆麟's avatar pete谢兆麟

图片选择器弹窗

parent 3458b157
......@@ -141,8 +141,8 @@ extension YHServiceCenterMainViewController : UITableViewDelegate,UITableViewDat
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
printLog("点击了 tableView Cell \(indexPath.row)")
// let vc = YHServiceCenterSecondViewController()
let vc = YHPersonInformMainViewController() //for test hjl
let vc = YHServiceCenterSecondViewController()
// let vc = YHPersonInformMainViewController() //for test hjl
self.navigationController?.pushViewController(vc)
}
......
......@@ -36,6 +36,7 @@ class YHMainApplicantInformationViewController: YHBaseViewController {
dataSource = viewModel.getDetailDataSource()
}
tableView.reloadData()
}
func setView() {
......
......@@ -6,12 +6,25 @@
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
/*
let view = YHImagePickerView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
view.backImage = { [weak self] image in
guard let self = self else { return }
}
let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view)
*/
import UIKit
class YHImagePickerView: UIView {
var backImage: ((UIImage) -> Void)?
var centerView: UIView!
var titleLabel: UILabel!
var closeButton: UIButton!
var takePhotoBtton: UIButton!
var selectPhotoButton: UIButton!
var cannalButton: UIButton!
var lineView: UIView!
override init(frame: CGRect) {
......@@ -43,7 +56,7 @@ class YHImagePickerView: UIView {
titleLabel = {
let label = UILabel()
label.text = "选择出生日期"
label.text = "请选择上传方式"
label.font = kFont(size: 17)
label.textColor = UIColor(hex:0x222222)
label.textAlignment = .left
......@@ -69,17 +82,67 @@ class YHImagePickerView: UIView {
make.top.equalTo(16)
}
lineView = {
takePhotoBtton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("拍照上传", for: .normal)
button.setTitleColor( UIColor(hex:0x222222), for: .normal)
button.addTarget(self, action: #selector(takePhoto), for: .touchUpInside)
return button
}()
centerView.addSubview(takePhotoBtton)
takePhotoBtton.snp.makeConstraints { make in
make.right.equalTo(-21)
make.height.equalTo(51)
make.left.equalTo(21)
make.top.equalTo(53)
}
selectPhotoButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("相册上传", for: .normal)
button.setTitleColor( UIColor(hex:0x222222), for: .normal)
button.addTarget(self, action: #selector(selectPhoto), for: .touchUpInside)
return button
}()
centerView.addSubview(selectPhotoButton)
selectPhotoButton.snp.makeConstraints { make in
make.right.equalTo(-21)
make.height.equalTo(51)
make.left.equalTo(21)
make.top.equalTo(105)
}
cannalButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("取消", for: .normal)
button.setTitleColor( UIColor(hex:0x909090), for: .normal)
button.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
return button
}()
centerView.addSubview(cannalButton)
cannalButton.snp.makeConstraints { make in
make.right.equalTo(-21)
make.height.equalTo(51)
make.left.equalTo(21)
make.top.equalTo(156)
}
for i in 0..<3 {
let view = UIView()
view.backgroundColor = UIColor(hex: 0xf0f0f0)
return view
}()
centerView.addSubview(lineView)
lineView.snp.makeConstraints { make in
make.left.equalTo(18)
make.top.equalTo(52)
make.height.equalTo(1)
make.right.equalTo(-18)
centerView.addSubview(view)
view.snp.makeConstraints { make in
make.left.equalTo(18)
make.top.equalTo(52 + 52 * i)
make.height.equalTo(1)
make.right.equalTo(-18)
}
}
}
......@@ -92,6 +155,35 @@ class YHImagePickerView: UIView {
removeFromSuperview()
}
@objc func takePhoto() {
if UIImagePickerController.isSourceTypeAvailable(.camera){
//创建图片控制器
let imagePicker = UIImagePickerController()
//设置代理
imagePicker.delegate = self
//设置来源
imagePicker.sourceType = .camera
//允许编辑
imagePicker.allowsEditing = true
//打开相机
UIViewController.current?.present(imagePicker, animated: true, completion: { () -> Void in
})
} else {
printLog("找不到相机")
}
}
@objc func selectPhoto() {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
// 这一句,开始调用图库
UIViewController.current?.present(imagePicker,animated: true)
}
}
}
extension YHImagePickerView: UIGestureRecognizerDelegate {
......@@ -103,3 +195,24 @@ extension YHImagePickerView: UIGestureRecognizerDelegate {
}
}
extension YHImagePickerView: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
// 将图片显示给UIImageView
if let block = backImage {
block(image)
self.dismiss()
}
} else {
printLog("pick image wrong")
}
// 收回图库选择界面
picker.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>NSCameraUsageDescription</key>
<string>cameraDesciption</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>photoLibraryDesciption</string>
</dict>
</plist>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment