1.xib
截屏2021-04-21 16.15.40.png 截屏2021-04-21 16.16.10.png
2.实现
///xib自定义View
import UIKit
class VisitorView: UIView {
//MARK:- 提供快速通过xib创建的类方法
///提供快速通过xib创建的类方法
class func visitorView() -> VisitorView {
return Bundle.main.loadNibNamed("VisitorView", owner: nil, options: [:])?.first as! VisitorView;
}
//MARK:- 属性
@IBOutlet weak var rotaryTable: UIImageView!
@IBOutlet weak var home: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var registered: UIButton!
@IBOutlet weak var login: UIButton!
//MARK:- 自定义属性函数
///设置属性
func setupVisitonViewInfo(homeName:String, titleLabel:String, rotaryBool:Bool) {
home.image = UIImage.init(named: homeName);
title.text = titleLabel;
rotaryTable.isHidden = rotaryBool;
}
///旋转动画
func addRotationAnim() {
/*
//1.
CAKeyframeAnimation 关键帧动画
let keyframe = CAKeyframeAnimation()
keyframe.values =
//2.
CABasicAnimation 核心动画
*/
//1.创建核心动画
let basic = CABasicAnimation.init(keyPath: "transform.rotation.z");
//2.设置动画属性
//开始位置
basic.fromValue = 0;
//结束动画
basic.toValue = Double.pi * 2;
//旋转次数
basic.repeatCount = MAXFLOAT;
//设置动画时间
basic.duration = 5;
//设置退到后台动画不停止
basic.isRemovedOnCompletion = false;
//3.添加动画
rotaryTable.layer.add(basic, forKey: nil);
}
}
3.调用
///懒加载访客视图
lazy var visitorView = VisitorView.visitorView();
网友评论