zoukankan      html  css  js  c++  java
  • 第12月第25天 ImagePickerSheetController

    1.ImagePickerSheetController

    open class ImagePickerSheetController: UIViewController, UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIViewControllerTransitioningDelegate {
    ...
        lazy var backgroundView: UIView = {
            let view = UIView()
            view.backgroundColor = UIColor(white: 0.0, alpha: 0.3961)
            view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ImagePickerSheetController.cancel)))
            
            return view
        }()
    ...
        override open func loadView() {
            super.loadView()
            
            view.addSubview(backgroundView)
            view.addSubview(tableView)
        }
    ...    
        // MARK: - Layout
        
        open override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            
            backgroundView.frame = view.bounds
            
            let tableViewHeight = Array(0..<tableView.numberOfRows(inSection: 1)).reduce(tableView(tableView, heightForRowAt: IndexPath(row: 0, section: 0))) { total, row in
                total + tableView(tableView, heightForRowAt: IndexPath(row: row, section: 1))
            }
    
            tableView.frame = CGRect(x: view.bounds.minX, y: view.bounds.maxY-tableViewHeight,  view.bounds.width, height: tableViewHeight)
        }
            let authorization = PHPhotoLibrary.authorizationStatus()
            
            if authorization == .notDetermined {
                PHPhotoLibrary.requestAuthorization({ (status) -> Void in
                    DispatchQueue.main.async(execute: { () -> Void in
                        self.pickProfileImage(tap)
                    })
                })
            }
            
            if authorization == .authorized {
                let controller = ImagePickerSheetController()
                
                controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "Action Title"), secondaryTitle: NSLocalizedString("Use this one", comment: "Action Title"), handler: { (_) -> () in
                    
                    self.presentCamera()
                    
                    }, secondaryHandler: { (action, numberOfPhotos) -> () in
                        controller.getSelectedImagesWithCompletion({ (images) -> Void in
                            self.profileImage = images[0]
                            self.userProfileImageView.image = self.profileImage
                        })
                }))
                
                controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .cancel, handler: nil, secondaryHandler: nil))
                
                present(controller, animated: true, completion: nil)
            }

    https://github.com/allenwong/30DaysofSwift/

  • 相关阅读:
    Android开发 ViewConfiguration View的配置信息类
    Android 开发 倒计时功能 转载
    Android 开发 关于7.0 FileUriExposedException异常 详解
    Android 开发 实现文本搜索功能
    Android 开发 Activity里获取View的宽度和高度 转载
    Android 开发 存储目录的详解
    Android 开发 Fresco框架点击小图显示全屏大图实现 ZoomableDraweeView
    Android 开发 将window变暗
    Android 开发 DisplayMetrics获取Android设备的屏幕高宽与其他信息
    Android 开发 DP、PX、SP转换详解
  • 原文地址:https://www.cnblogs.com/javastart/p/7593085.html
Copyright © 2011-2022 走看看