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()

}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 今天我们来学一下tom猫的动画吧😊 首先我们先找到一个tom猫的一系列动作。添加到工程中。 class AppDe...
    cyyy520阅读 4,262评论 0 2
  • 一、九宫格1.1 ****方法****1 ****只能创建(****ij****)个对象* 1.2 ****方法*...
    AsaGuo阅读 3,157评论 0 1
  • // // ViewController.m // TOM // // Created by lanou on 1...
    丶Tiamo阅读 4,191评论 1 0
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 12,729评论 6 30
  • -(void)viewDidLoad [super viewDidLoad];{ //序列帧动画要播放的图片数组 ...
    墨染倾阅读 1,306评论 0 0

友情链接更多精彩内容