“Yeah It’s on. ”
正文
- @_silgen_name(“方法名”) 无需桥接OC 不需要引用 即可在swift内实现调用OC方法
- swift判等:protocol Equatable { func ==(lhs: Self, rhs: Self) -> Bool }
- associatedtype 泛型占位
- Xcode(13.2.1)后版本对歧义命名有要求,例如:
class Test: UIView { public var cornerRadius: CGFloat { get { layer.cornerRadius } set { layer.cornerRadius = newValue } } }
调用时候则会报错歧义。
let test = Test() test.cornerRadius = 12
- 执行震动
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
- 关于CABasicAnimation动画处理
- 设置属性时候注意设置isRemovedOnCompletion = false,如果未设置此属性会在切换页面时导致主线程动画丢失
- 例子如下:
let rotaionAniamtionAnima = CABasicAnimation(keyPath: "transform.rotation.z") let num:CGFloat = .pi*(-3.5) rotaionAniamtionAnima.toValue = num rotaionAniamtionAnima.duration = 2 rotaionAniamtionAnima.repeatCount = MAXFLOAT rotaionAniamtionAnima.isRemovedOnCompletion = false backLayer.add(rotaionAniamtionAnima, forKey: "rotaionAniamtion")
- 例子如下:
extension UIView { /// 指定圆角 /// /// - Parameters: /// - corners: 需要实现为圆角的角,可传入多个 /// - radii: 圆角半径 func extCorner(corners: UIRectCorner, radii: CGFloat) { let maskPath = UIBezierPath.init(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radii, height: radii)) let maskLayer = CAShapeLayer() maskLayer.frame = self.bounds maskLayer.path = maskPath.cgPath self.layer.mask = maskLayer } }
CaseIterable
-
enum可遵循的协议,可获取allCases属性,用于表示一个包含枚举所有成员的集合。
-
设置默哀模式
private func setSilenceMode(_ vc: UIViewController) { let overlay = UIView(frame: vc.view.bounds) overlay.isUserInteractionEnabled = false overlay.translatesAutoresizingMaskIntoConstraints = false overlay.backgroundColor = .lightGray overlay.layer.compositingFilter = "saturationBlendMode" vc.view.addSubview(overlay) vc.view.bringSubviewToFront(overlay) overlay.snp.makeConstraints { make in make.edges.equalToSuperview() } }
结束
欢迎交流。
—— Ade