Commit 5b930306 authored by David黄金龙's avatar David黄金龙

删除不使用的文件

parent 79457af8
This diff is collapsed.
...@@ -60,7 +60,7 @@ extension AppDelegate { ...@@ -60,7 +60,7 @@ extension AppDelegate {
IQKeyboardManager.shared.shouldResignOnTouchOutside = true // 控制点击背景是否收起键盘 IQKeyboardManager.shared.shouldResignOnTouchOutside = true // 控制点击背景是否收起键盘
//webView 预加载 //webView 预加载
BsWebViewPreloadManager.share.addPreloadingView() // BsWebViewPreloadManager.share.addPreloadingView()
// //
customAppearance() customAppearance()
......
...@@ -19,13 +19,6 @@ class YHNavigationController: UINavigationController { ...@@ -19,13 +19,6 @@ class YHNavigationController: UINavigationController {
self.interactivePopGestureRecognizer?.delegate = self self.interactivePopGestureRecognizer?.delegate = self
} }
// override func viewWillLayoutSubviews() {
// super.viewWillLayoutSubviews()
// if #available(iOS 14.0, *){
// self.navigationBar.topItem?.backButtonDisplayMode = .minimal
// }
// }
override func pushViewController(_ viewController: UIViewController, animated: Bool) { override func pushViewController(_ viewController: UIViewController, animated: Bool) {
// 隐藏要push的控制器的tabbar // 隐藏要push的控制器的tabbar
if animated == true { if animated == true {
......
This diff is collapsed.
//
// BsKVOHelper.swift
// BaiSiSMApp
//
// Created by davidhuang on 2022/10/19.
// Copyright © 2022 www.davidhuang.com. All rights reserved.
//
import UIKit
///解决重复添加;解决重复移除;解决未添加却移除
open class BsKVOHelper {
class Container: Equatable {
static func == (lhs: BsKVOHelper.Container, rhs: BsKVOHelper.Container) -> Bool {
guard let lObserver = lhs.observer,
let lObject = lhs.object,
let rObserver = rhs.observer,
let rObject = rhs.object else {
return false
}
if lObserver == rObserver, lObject == rObject{
return lhs.keyPath == rhs.keyPath
}
return false
}
var observer: Int?
var object: Int?
var keyPath: String
init(observer: Int?, object: Int?, keyPath: String) {
self.observer = observer
self.object = object
self.keyPath = keyPath
}
func clear(){
observer = nil
object = nil
}
}
private var containers: [Container] = []
public init(){
}
open func add(observer: NSObject,toObject object: NSObject,forKeyPath keyPath: String, options: NSKeyValueObservingOptions = [], context: UnsafeMutableRawPointer?){
let aContainer = Container(observer: observer.hashValue, object: object.hashValue, keyPath: keyPath)
if containers.contains(where: { (thisContainer) -> Bool in
return aContainer == thisContainer
}){
return
}
containers.append(aContainer)
object.addObserver(observer,forKeyPath: keyPath, options: options, context: context)
}
open func remove(observer: NSObject,atObject object: NSObject,forKeyPath keyPath: String){
let aContainer = Container(observer: observer.hashValue, object: object.hashValue, keyPath: keyPath)
if let first = containers.first(where: { (thisContainer) -> Bool in
return aContainer == thisContainer
}){
object.removeObserver(observer, forKeyPath: keyPath)
first.clear()
}
}
}
//
// BsMapManager.swift
// BaiSiSMApp
//
// Created by Davidhuang on 2022/12/15.
// Copyright © 2022 www.davidhuang.com. All rights reserved.
//
import UIKit
import MapKit
class BsMapManager {
// MARK: - 属性
static let sharedInstance = BsMapManager()
public let hasQqMap: Bool = UIApplication.shared.canOpenURL(URL(string: "qqmap://")!)
public let hasIosaMap: Bool = UIApplication.shared.canOpenURL(URL(string: "iosamap://")!)
public let hasBaiduMap: Bool = UIApplication.shared.canOpenURL(URL(string: "baidumap://")!)
// 当前位置或起始位置
var currentLocation: CLLocationCoordinate2D!
var currentAddress: String = ""
// 目标位置
var targetLocation: CLLocationCoordinate2D!
var targetAddress: String = ""
// MARK: - 导航位置初始化
func initNavi(currentLoc: CLLocationCoordinate2D! = nil, currentAdd: String = "", targetLoc: CLLocationCoordinate2D!, targetAdd: String) {
if currentLoc != nil {
currentLocation = currentLoc
}
currentAddress = currentAdd
if targetLoc != nil {
targetLocation = targetLoc
}
targetAddress = targetAdd
}
// MARK: - Apple地图导航
func naviWithAppleMap() {
if targetLocation == nil {
return
}
// 起始位置
let fromLocation = MKMapItem.forCurrentLocation()
fromLocation.name = "我的位置"
// 目标位置
let toCoor = CLLocationCoordinate2D(latitude: targetLocation!.latitude, longitude: targetLocation!.longitude)
let toLocation = MKMapItem(placemark: MKPlacemark(coordinate: toCoor, addressDictionary: [:]))
toLocation.name = targetAddress
// 打开地图
MKMapItem.openMaps(with: [fromLocation, toLocation],
launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsShowsTrafficKey: NSNumber(true)])
}
// MARK: - 百度地图导航
func naviWithBaiduMap() {
if targetLocation == nil {
return
}
/// 请求格式:
/// baidumap://map/direction?origin=34.264642646862,108.95108518068&destination=40.007623,116.360582&coord_type=bd09ll&mode=driving&src=ios.baidu.openAPIdemo
var urlString: String = "baidumap://map/direction?"
// 起始位置
let origin: String = "我的位置"
urlString = urlString + "origin=\(origin)"
// 目标位置
let destination: String = "\(targetLocation!.latitude),\(targetLocation!.longitude)"
let name: String = targetAddress
urlString = urlString + "&destination=name:\(name)|latlng:\(destination)"
/// 可选的坐标系统:
/// bd09ll(百度经纬度坐标)
/// bd09mc(百度墨卡托坐标)
/// gcj02(经国测局加密的坐标)
/// wgs84(gps获取的原始坐标)
urlString = urlString + "&coord_type=gcj02&mode=driving&src=ios.ftsafe.FTSmartSudentCard"
urlString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: urlString)!, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: urlString)!)
}
}
// MARK: - 腾讯地图导航
func naviWithQqMap() {
if targetLocation == nil {
return
}
/// 请求格式:
/// qqmap://map/routeplan?type=drive&from=清华&fromcoord=39.994745,116.247282&to=怡和世家&tocoord=39.867192,116.493187&referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77
/// 这里可能需要开发者key,即referer
var urlString: String = "qqmap://map/routeplan?type=drive"
let origin: String = "我的位置"
urlString = urlString + "&from=\(origin)&fromcoord=CurrentLocation"
let destination: String = "\(targetLocation!.latitude),\(targetLocation!.longitude)"
let name: String = targetAddress
urlString = urlString + "&to=\(name)&tocoord=\(destination)"
urlString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: urlString)!, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: urlString)!)
}
}
// MARK: - 高德地图导航
func naviWithAMap() {
if targetLocation == nil {
return
}
/// 请求格式:
/// iosamap://path?sourceApplication=applicationName&sid=&slat=39.92848272&slon=116.39560823&sname=A&did=&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&t=0
var urlString: String = "iosamap://path?sourceApplication=FTSmartSudentCard"
let name: String = targetAddress
urlString = urlString + "&dlat=\(targetLocation!.latitude)&dlon=\(targetLocation!.longitude)&dname=\(name)&dev=0&t=0"
urlString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: urlString)!, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: urlString)!)
}
}
}
//
// BsPageContentView.swift
// GDKit
//
// Created by GDKit on 01/11/2022.
// Copyright (c) 2022 GDKit. All rights reserved.
//
import UIKit
@objc public protocol BsPageContentViewDelegate : AnyObject {
func pageContentView(_ contentView : BsPageContentView, progress : CGFloat, sourceIndex : Int, targetIndex : Int)
}
private let ContentCellID = "BsContentCellID"
open class BsPageContentView: UIView {
// MARK: - 定义属性
fileprivate var childVcs : [UIViewController]
fileprivate weak var parentVC : UIViewController?
fileprivate var startOffsetX : CGFloat = 0
fileprivate var isForbidScrollDelegate : Bool = false
@objc public weak var delegate : BsPageContentViewDelegate?
public var isScrollEnabled: Bool? {
didSet {
if let isScrollEnabled = isScrollEnabled {
collectionView.isScrollEnabled = isScrollEnabled
}
}
}
@objc public func banScrollEnabled() {
collectionView.isScrollEnabled = false
}
fileprivate func getLayout() -> UICollectionViewFlowLayout {
let layout = UICollectionViewFlowLayout()
layout.itemSize = self.bounds.size
layout.minimumLineSpacing = 0
layout.minimumInteritemSpacing = 0
layout.scrollDirection = .horizontal
return layout
}
// MARK: - 懒加载属性
fileprivate lazy var collectionView : UICollectionView = {[weak self] in
// 1.创建layout
let layout = self?.getLayout() ?? UICollectionViewFlowLayout()
// 2.创建UICollectionView
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.backgroundColor = .clear//groupTableViewBackground
collectionView.showsHorizontalScrollIndicator = false
collectionView.isPagingEnabled = true
collectionView.bounces = false
collectionView.dataSource = self
collectionView.delegate = self
collectionView.scrollsToTop = false
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: ContentCellID)
return collectionView
}()
// MARK: - 自定义构造函数
@objc public init(frame: CGRect, childVcs : [UIViewController], parentViewController : UIViewController?) {
self.childVcs = childVcs
self.parentVC = parentViewController
super.init(frame: frame)
// 设置UI
setupUI()
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// MARK: - 设置UI界面
extension BsPageContentView {
fileprivate func setupUI() {
// 1.将所有的子控制器添加父控制器中
for childVc in childVcs {
parentVC?.addChild(childVc)
}
// 2.添加UICollectionView,用于在Cell中存放控制器的View
addSubview(collectionView)
collectionView.frame = bounds
}
public func refreshRect() {
collectionView.frame = bounds
collectionView.collectionViewLayout = self.getLayout()
}
}
// MARK: - 遵守UICollectionViewDataSource
extension BsPageContentView : UICollectionViewDataSource {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return childVcs.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// 1.创建Cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ContentCellID, for: indexPath)
// 2.给Cell设置内容
for view in cell.contentView.subviews {
view.removeFromSuperview()
}
let childVc = childVcs[(indexPath as NSIndexPath).item]
childVc.view.frame = cell.contentView.bounds
cell.contentView.addSubview(childVc.view)
return cell
}
}
// MARK: - 遵守UICollectionViewDelegate
extension BsPageContentView : UICollectionViewDelegate {
public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
isForbidScrollDelegate = false
startOffsetX = scrollView.contentOffset.x
}
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
// 0.判断是否是点击事件
if isForbidScrollDelegate { return }
// 1.定义获取需要的数据
var progress : CGFloat = 0
var sourceIndex : Int = 0
var targetIndex : Int = 0
// 2.判断是左滑还是右滑
let currentOffsetX = scrollView.contentOffset.x
let scrollViewW = scrollView.bounds.width
if currentOffsetX > startOffsetX { // 左滑
// 1.计算progress
progress = currentOffsetX / scrollViewW - floor(currentOffsetX / scrollViewW)
// 2.计算sourceIndex
sourceIndex = Int(currentOffsetX / scrollViewW)
// 3.计算targetIndex
targetIndex = sourceIndex + 1
if targetIndex >= childVcs.count {
targetIndex = childVcs.count - 1
}
// 4.如果完全划过去
if currentOffsetX - startOffsetX == scrollViewW {
progress = 1
targetIndex = sourceIndex
}
} else { // 右滑
// 1.计算progress
progress = 1 - (currentOffsetX / scrollViewW - floor(currentOffsetX / scrollViewW))
// 2.计算targetIndex
targetIndex = Int(currentOffsetX / scrollViewW)
// 3.计算sourceIndex
sourceIndex = targetIndex + 1
if sourceIndex >= childVcs.count {
sourceIndex = childVcs.count - 1
}
}
// 3.将progress/sourceIndex/targetIndex传递给titleView
delegate?.pageContentView(self, progress: progress, sourceIndex: sourceIndex, targetIndex: targetIndex)
}
}
// MARK: - 对外暴露的方法
extension BsPageContentView {
@objc public func setCurrentIndex(_ currentIndex : Int) {
// 1.记录需要进制执行代理方法
isForbidScrollDelegate = true
// 2.滚动正确的位置
let offsetX = CGFloat(currentIndex) * collectionView.frame.width
collectionView.setContentOffset(CGPoint(x: offsetX, y: 0), animated: false)
}
}
//
// BsPresentView.swift
// BaiSiSMApp
//
// Created by Davidhuang on 2022/12/15.
// Copyright © 2022 www.davidhuang.com. All rights reserved.
//
import UIKit
/// view.tag = 98 由下往上推出
/// view.tag = 99 由frame起点缩放
open class BsPresentView: UIView {
var animated: Bool = true
///由下往上推出
@objc public func bs_showView(_ view: UIView, isTapEnabled: Bool = true) {
self.animated = true
bs_showView(view, isTapEnabled: isTapEnabled, animated: true)
}
///由下往上推出
@objc public func bs_showView(_ view: UIView, isTapEnabled: Bool = true, animated: Bool) {
// self.keyWindow = [[[UIApplication sharedApplication] delegate] window];
// self.keyVC = self.keyWindow.rootViewController;
// self.frame = self.keyWindow.bounds;
view.tag = 98
self.animated = animated
self.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
self.backgroundColor = UIColor.black.withAlphaComponent(0.4)
UIApplication.shared.keyWindow?.addSubview(self)
let topView = UIView(frame: self.frame)
self.addSubview(topView)
topView.height = self.height - view.height
if isTapEnabled == true {
let tap = UITapGestureRecognizer(target: self, action: #selector(bs_closeView))
topView.addGestureRecognizer(tap)
}
self.addSubview(view)
view.top = self.height
if (animated == true) {
UIView.animate(withDuration: 0.25) {
view.top = self.height - view.height
}
}else{
view.top = self.height - view.height
}
}
///由frame为起点缩放
@objc public func bs_showView(_ view: UIView, frame: CGRect) {
view.tag = 99
self.animated = true
//view.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: 0, height: 0)
self.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
//self.backgroundColor = UIColor.black.withAlphaComponent(0.4)
UIApplication.shared.keyWindow?.addSubview(self)
let backView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
self.addSubview(backView)
let tap = UITapGestureRecognizer(target: self, action: #selector(bs_closeView))
backView.addGestureRecognizer(tap)
backView.isUserInteractionEnabled = false
self.addSubview(view)
view.frame = frame
if (animated == true) {
var offsetX = frame.size.width / 2
if frame.origin.x < (UIScreen.main.bounds.size.width - frame.size.width)/2 {
offsetX = -frame.size.width / 2
}
let offsetY = -frame.size.height / 2
view.transform = __CGAffineTransformMake(0.01, 0, 0, 0.01, offsetX, offsetY)
//view.layer.anchorPoint = CGPoint(x: 0, y: 0) //锚点
UIView.animate(withDuration: 0.3) {
view.alpha = 1.0
view.transform = __CGAffineTransformMake(1.05, 0, 0, 1.0, 0, 0)
} completion: { success in
UIView.animate(withDuration: 0.1) {
view.transform = __CGAffineTransformMake(1, 0, 0, 1, 0, 0)
} completion: { success in
// 恢复原位
view.transform = CGAffineTransform.identity
backView.isUserInteractionEnabled = true
}
}
}else{
view.frame = frame
}
}
// override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// self.bs_closeView()
// }
@objc public func bs_closeView() {
guard let view = self.subviews.last, self.subviews.count == 2 else {
self.removeFromSuperview()
return
}
if (animated == true) {
if view.tag == 99 {
let frame = view.frame
// 动画由大变小
view.transform = __CGAffineTransformMake(1, 0, 0, 1, 0, 0)
UIView.animate(withDuration: 0.2) {
var offsetX = frame.size.width / 2
if frame.origin.x < (UIScreen.main.bounds.size.width - frame.size.width)/2 {
offsetX = -frame.size.width / 2
}
let offsetY = -frame.size.height / 2
view.transform = __CGAffineTransformMake(0.01, 0, 0, 0.01, offsetX, offsetY)
} completion: { success in
view.transform = CGAffineTransform.identity
view.alpha = 0.0
self.removeFromSuperview()
}
} else {
UIView.animate(withDuration: 0.25, animations: {
view.top = self.height
}) { (finished) in
self.removeFromSuperview()
}
}
}else{
view.top = self.height
self.removeFromSuperview()
}
}
public class func bs_closeView() {
for view in UIApplication.shared.keyWindow?.subviews ?? [] {
if let view = view as? BsPresentView {
view.bs_closeView()
break
}
}
}
}
extension UIView {
@objc public func bs_closeViewToPresentView() {
if let presentView = self.superview as? BsPresentView {
presentView.bs_closeView()
}
}
}
//
// BskWebViewPreloadManager.swift
// BaiSiSMApp
//
// Created by davidhuang on 2022/11/22.
// Copyright © 2022 www.davidhuang.com. All rights reserved.
//
import UIKit
import WebKit
class BsWebViewPreloadManager : NSObject {
private var dicPreloadedViews : [String : AnyObject] = [:]
static let share = BsWebViewPreloadManager()
override init() {
super.init()
addPreloadingView()
}
// /**
// 根据URL 预初始化若干WebView
// */
// - (void)addPreloadingView:(NSArray *)urls {
// for (NSString *url in urls) {
// if (![self.urls containsObject:url]) {
// [self.urls addObject: url];
// ReuseWebView *webView = [self createWebView];
// [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
// [self.preloadedViews addEntriesFromDictionary:@{url:webView}];
// }
// }
// }
}
// MARK: - 私有方法 methods
extension BsWebViewPreloadManager {
private func getWebview(urlString : String) -> WKWebView {
if let wk = dicPreloadedViews[urlString] {
return wk as! WKWebView
}
return createWebView(urlString: urlString)
}
private func createWebView(urlString : String) -> WKWebView {
let jScript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"
let userScript = WKUserScript(source: jScript, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true)
let userContentController = WKUserContentController()
userContentController.addUserScript(userScript)
let cfg = WKWebViewConfiguration()
cfg.allowsInlineMediaPlayback = true
cfg.mediaTypesRequiringUserActionForPlayback = []
cfg.userContentController = userContentController
let wv = WKWebView(frame: UIScreen.main.bounds,configuration: cfg)
if let nsURL = URL(string: urlString){
let request = URLRequest(url: nsURL)
wv.load(request)
return wv
}
return WKWebView()
}
#if DEBUG
func onlyCreateWebView() -> WKWebView {
let jScript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"
let userScript = WKUserScript(source: jScript, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true)
let userContentController = WKUserContentController()
userContentController.addUserScript(userScript)
let cfg = WKWebViewConfiguration()
cfg.allowsInlineMediaPlayback = true
cfg.mediaTypesRequiringUserActionForPlayback = []
cfg.userContentController = userContentController
let wv = WKWebView(frame: UIScreen.main.bounds,configuration: cfg)
return wv
}
#endif
}
// MARK: - public methods
extension BsWebViewPreloadManager {
func addPreloadingView() {
let arrUrl = [
BsConstant.URL.medical_center_url]
for item in arrUrl {
let wv = createWebView(urlString: item)
dicPreloadedViews[item] = wv
}
}
func getWebView(urlString : String) -> WKWebView {
let urls = dicPreloadedViews.keys
if urls.contains(urlString) == false {
return getWebview(urlString: urlString)
} else {
let wk = createWebView(urlString: urlString)
dicPreloadedViews[urlString] = wk
return wk
}
}
}
//
// MCClipImageTool.swift
// MCAPI
//
// Created by MC on 2018/9/18.
// Copyright © 2018年 MC. All rights reserved.
//
import UIKit
extension UIImage {
/**
* 翻转图片
*/
func rotationImage(orientation:UIImage.Orientation) -> UIImage {
var rotate : Double = 0.0;
var rect = CGRect.init()
var translateX : CGFloat = 0.0;
var translateY : CGFloat = 0.0;
var scaleX : CGFloat = 1.0;
var scaleY : CGFloat = 1.0;
let imageWidth = self.size.width
let imageHeight = self.size.height
// 根据方向旋转
switch (orientation) {
case .left:
rotate = Double.pi / 2;
rect = CGRect.init(x: 0, y: 0, width: imageHeight, height: imageWidth)
translateX = 0
translateY = -rect.size.width;
scaleY = rect.size.width/rect.size.height;
scaleX = rect.size.height/rect.size.width;
break;
case .right:
rotate = 33 * Double.pi / 2;
rect = CGRect.init(x: 0, y: 0, width: imageHeight, height: imageWidth)
translateX = -rect.size.height;
translateY = 0;
scaleY = rect.size.width/rect.size.height;
scaleX = rect.size.height/rect.size.width;
break;
case .down:
rotate = Double.pi
rect = CGRect.init(x: 0, y: 0, width: imageWidth, height: imageHeight)
translateX = -rect.size.width;
translateY = -rect.size.height;
break;
default:
rotate = 0.0;
rect = CGRect.init(x: 0, y: 0, width: imageWidth, height: imageHeight)
translateX = 0;
translateY = 0;
break;
}
//做CTM变换,并绘制图片
UIGraphicsBeginImageContext(rect.size);
let context = UIGraphicsGetCurrentContext();
context?.translateBy(x: 0, y: rect.size.height)
context?.scaleBy(x: 1, y: -1)
context?.rotate(by: CGFloat(rotate))
context?.translateBy(x: translateX, y: translateY)
context?.scaleBy(x: scaleX, y: scaleY)
context?.draw(self.cgImage!, in: CGRect.init(x: 0, y: 0, width: rect.size.width, height: rect.size.height))
let newPic = UIGraphicsGetImageFromCurrentImageContext();
return newPic!
}
/**
* 判断图片和裁剪框的关系类型
*/
func judgeRelationTypeWithCropSize(_ cropSize: CGSize) -> Int {
var relationType = 0
let crop_W = cropSize.width
let crop_H = cropSize.height
let image_W = self.size.width
let image_H = self.size.height
let imageRadio = image_W / image_H
let cropRadio = crop_W / crop_H
/** 裁切框宽高比 > 1
0. 裁切框宽高比 >= 图片宽高比 imageView宽固定,高适配
1. 裁切框宽高比 < 图片宽高比 imageView高固定,宽适配
*/
/** 裁切框宽高比 = 1
2. 裁切框宽高比 >= 图片宽高比 imageView宽固定,高适配
3. 裁切框宽高比 < 图片宽高比 imageView高固定,宽适配
*/
/** 裁切框宽高比 < 1
4. 裁切框宽高比 >= 图片宽高比 imageView宽固定,高适配
5. 裁切框宽高比 < 图片宽高比 imageView高固定,宽适配
*/
if cropRadio > 1 {
if cropRadio >= imageRadio {
relationType = 0
} else {
relationType = 1
}
} else if cropRadio == 1 {
if cropRadio >= imageRadio {
relationType = 2
} else {
relationType = 3
}
} else {
if cropRadio >= imageRadio {
relationType = 4
} else {
relationType = 5
}
}
return relationType
}
// 将图片裁剪为圆形
func clipCircularImage() -> UIImage {
let imageWidth = self.size.width
let imageHeight = self.size.height
let arcCenterX = imageWidth / 2
let arcCenterY = imageHeight / 2
let radius = arcCenterX > arcCenterY ? arcCenterY : arcCenterX
UIGraphicsBeginImageContext(self.size)
let context = UIGraphicsGetCurrentContext()
context!.beginPath()
context?.addArc(center: CGPoint.init(x: arcCenterX, y: arcCenterY), radius: radius, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: false)
context?.clip()
self.draw(in: CGRect.init(x: 0, y: 0, width: imageWidth, height: imageHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return newImage!
}
}
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