美文网首页
Tom猫的动画

Tom猫的动画

作者: cyyy520 | 来源:发表于2016-11-21 17:14 被阅读0次

今天我们来学一下tom猫的动画吧😊 首先我们先找到一个tom猫的一系列动作。添加到工程中。

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.8931787501, green: 0.9535736618, blue: 1, alpha: 1)

self.window?.makeKeyAndVisible()

self.window?.rootViewController = UIViewController()

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

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.9764705896, green: 0.8485177922, blue: 0.9226891988, alpha: 1)

//aImageView.image = UIImage(named:"happy.png")

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 = UIColor.clear

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

}

func applicationWillResignActive(_ application: UIApplication) {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

func applicationDidEnterBackground(_ application: UIApplication) {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

func applicationWillEnterForeground(_ application: UIApplication) {

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

func applicationDidBecomeActive(_ application: UIApplication) {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

func applicationWillTerminate(_ application: UIApplication) {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

}

相关文章

  • Tom猫的动画

    今天我们来学一下tom猫的动画吧? 首先我们先找到一个tom猫的一系列动作。添加到工程中。 class AppDe...

  • Android手机网络强弱

    Tom猫哦哦哦

  • 初代网红系列之十九:天仙妹妹

    如果你是一个资深互联网玩家,那么你一定听说过tom网,现在我们说tom的时候都会不自觉的跟一只动画猫产生联系,但是...

  • TOM猫

    import UIKit @UIApplicationMain class AppDelegate: UIResp...

  • Tom猫

    1.//按钮函数 - (IBAction)beginAction:(UIButton*)sender { NSLo...

  • 《Catch me if you can》中的博弈

    电影《Catch me if you can》被译为《猫鼠游戏》,使我一下就联想到了小时候常看的动画片《Tom a...

  • ToM猫 (UIImage )

    将上图中的Main interface 中的 Main 删掉,然后将放有照片的文件夹拖到程序中,如上图左侧。自己在...

  • Tom猫1

    -(void)viewDidLoad [super viewDidLoad];{ //序列帧动画要播放的图片数组 ...

  • TOM猫2

    精简算法 -(void)tomCatAnimationWithName:(NSString *)name /...

  • Tom-猫

网友评论

      本文标题:Tom猫的动画

      本文链接:https://www.haomeiwen.com/subject/alvupttx.html