目录
之前我写了一篇名为:xcode写framework静态库脚本文件合并fat文件教程和踩坑
的文章:https://blog.csdn.net/boildoctor/article/details/112259356
但还是没说具体怎么用swift建立framework静态库,这里补上教程:
新建项目
File->new->Project->Framework,起一个项目名,语言选择swift 如下图


设置相关参数
1.设置静态库
build settings -> Mach-O Type设置(Static Library) ,如下图

2.设置版本号
general->Deployment Info -> 设置 ios9.0,

3. 设置生成fat包
Build Active Architecture Only(NO,生成fat包,包括模拟器x86_64和arm64)

4. Dead Code Stripping(NO)

创建swift系统类扩展
新建文件一个swift文件,起名UIView+AnimateExtension.swift,这个系统类扩展作用就是执行以后可以直接摇动UIView
//
// UIView+AnimateExtension.swift
// tdwUIView+AnimateExtension
//
// Created by tdw on 2021/1/5.
//
import UIKit
extension UIView{
/**
摇动当前view水平方向
*/
@objc public func shakeAnimationH() {
// 抖一抖
self.layer.removeAnimation(forKey: "error")
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.values = [-16, 0, 16, 0]
animation.duration = 0.2
animation.repeatCount = 3
self.layer.add(animation, forKey: "error")
}
/**
摇动当前view水平方向
*/
@objc public func shakeAnimationH(duration:Double,repeatCount:Float) {
// 抖一抖
self.layer.removeAnimation(forKey: "error")
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.values = [-16, 0, 16, 0]
animation.duration = duration
animation.repeatCount = repeatCount
self.layer.add(animation, forKey: "error")
}
/**
摇动当前view垂

本文详细介绍了如何在Xcode中创建Swift静态库,设置相关参数,包括设置为静态库、版本号、生成fat包,以及处理DeadCodeStripping。此外,还展示了创建系统类扩展,并提供了脚本自动化合并framework的步骤,包括解决合并过程中遇到的问题。最后,讲解了在Swift和Objective-C项目中如何引用和使用这个静态库。

3779

被折叠的 条评论
为什么被折叠?



