TOM猫

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

//添加一个图片的属性

var imageView:UIImageView!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

self.window = UIWindow(frame: UIScreen.main.bounds)

self.window?.backgroundColor = #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)

self.window?.makeKeyAndVisible()

self.window?.rootViewController = UIViewController()

//UImageView 图片展示控件,因为UIImage本事不具备显示功能,想要展示UIImage必须借助于UImageView

let aImageView = UIImageView(frame: CGRect(x: 10, y: 10, width: (self.window?.bounds.size.width)! - 20, height:(self.window?.bounds.size.height)! - 20 ))

aImageView.backgroundColor = #colorLiteral(red: 0.9568627477, green: 0.6588235497, blue: 0.5450980663, alpha: 1)

//附一张图片

// aImageView.image = UIImage(named:"angry_00.jpg")

aImageView.image = #imageLiteral(resourceName: "angry_00.jpg")

self.window?.addSubview(aImageView)

//使用UIImageView播放一组图片

//1.准备一组图片对象

var imageArray:[UIImage] = Array()

for i in 0...25 {

//准备图片名

let imageName = String(format: "angry_%02d.jpg", i)

//初始化图片对象

let image = UIImage(named:imageName)

//将图片放进数组中

imageArray.append(image!)

}

//给播放的数组赋值

aImageView.animationImages = imageArray

//2.设置动画持续时间

aImageView.animationDuration = 2.0

//3.设置动画重复次数

aImageView.animationRepeatCount = 1

//4.开始动画

//aImageView.startAnimating()

let angryButton = UIButton(frame:CGRect(x: 157, y: 530, width: 100, height: 100))

//angryButton.backgroundColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)

self.window?.addSubview(angryButton)

angryButton.addTarget(self, action: #selector(angryButtonAction), for: .touchUpInside)

//给属性imageView赋值

self.imageView = aImageView

return true

}

//MARK:- button的点击事件

func angryButtonAction(){

//开始动画

self.imageView.startAnimating()

}


TOM猫_第1张图片
TOM猫_第2张图片
TOM猫_第3张图片
TOM猫_第4张图片

你可能感兴趣的:(TOM猫)