当先锋百科网

首页 1 2 3 4 5 6 7

1.demo截图

swift版本的项目打开会有一些语法错误, 所以我还是用的oc版本的

HXPhotoPicker - github

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

2.选取头像:需要把demo中WxMomentHeaderView.m和WxMomentViewController.m中对HXPhotoManager的设置合并在一起

//
//  GetImageTest.swift
//  Fei
//
//  Created by macivi on 2022/3/30.
//

import UIKit

var GImage:UIImage = UIImage()

class GetImageTest: UIViewController {

    @IBAction func compressBtnClick(_ sender: UIButton) {
        let data = GImage.compressImage()
        imageView.image = UIImage(data: data)
        printXY(data.count, obj: self, line: #line)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        imageView.image = UIImage(named: "banner")
    }

    @IBOutlet var imageView: UIImageView!
    @IBOutlet var btn: UIButton!
    
    lazy var manager:HXPhotoManager = {
        let manager = HXPhotoManager()
        manager.configuration.type = .wxMoment
        manager.configuration.localFileName = "hx_WxMomentPhotoModels"
        manager.configuration.showOriginalBytes = true
        manager.configuration.showOriginalBytesLoading = true
        manager.selectPhotoFinishDismissAnimated = true
        manager.cameraFinishDismissAnimated = true
        manager.type = .photo
        manager.configuration.singleJumpEdit = true
        manager.configuration.singleSelected = true
        manager.configuration.lookGifPhoto = false
        manager.configuration.lookLivePhoto = false
        manager.configuration.photoEditConfigur.aspectRatio = .type_1x1
        manager.configuration.photoEditConfigur.onlyCliping = true
        return manager
    }()
    
    @IBAction func btnClick(_ sender: Any) {
        print("点击事件")
        let model1 = HXPhotoBottomViewModel()
        model1.title = "更换头像"
        model1.titleColor = .hexColor(hexValue: 0x999999)
        model1.cellHeight = 40
        model1.titleFont = UIFont.systemFont(ofSize: 13)
        model1.canSelect = false
        
        let model2 = HXPhotoBottomViewModel()
        model2.title = "拍一张"
        
        let model3 = HXPhotoBottomViewModel()
        model3.title = "从手机相册选择"
        
        weak var weakSelf = self
        
        HXPhotoBottomSelectView.show(withModels: [model1,model2,model3]) { (index, photoBottomViewModel) in
            printXY(index, obj: self, line: #line)
            if index == 1{
                //拍照
                weakSelf?.hx_presentCustomCameraViewController(with: weakSelf?.manager, done: { (photoModel, customCameraViewController) in
                    photoModel?.getAssetURL(success: { (url, photoModelMediaSubType, bool, photoModel) in
                        printXY(url, obj: self, line: #line)
                        let nsdata = NSData(contentsOf: url!)
                        let data:Data = nsdata as! Data
                        let image = UIImage(data: data)
                        GImage = image!
                        weakSelf?.imageView.image = image
                        printXY(image, obj: self, line: #line)
                        printXY(data.count, obj: self, line: #line)
                    }, failed: nil)
                }, cancel: nil)
                
            }else if index == 2{
                //从相册选择
                weakSelf?.hx_presentSelectPhotoController(with: weakSelf?.manager, didDone: { (photoModelAllLists, photoModelPhotoLists, photoModelVideoLists, isOriginal, viewController, photoManager) in
                    let model = photoModelAllLists?.first
                    // 因为是编辑过的照片所以直接取
                    let image = model?.photoEdit?.editPreviewImage
                    GImage = image!
                    weakSelf?.imageView.image = image
                }, cancel: nil)
            }
        } cancelClick: {}
        
    }

}