IOS开发之——TOM猫(19)

一 概述

本文介绍TOM的简单开发示例,涉及到的知识点:

  • 点击某个区域或按钮执行动画

  • 多图及大图加载时的内存分配与释放

<!--more-->

二 效果图

 

三 布局

  • View中有UIImageView(要执行动画)和UIButton(鸟)和UIButton(头部)

  • 其中UIButton(鸟)中设置的text为eat(与要执行的动画开始名字相同)和tag(30与动画个数相同)

  • 其中UIButton(头部)中设置的text为knockout(与要执行的动画开始名字相同)和tag(81与动画个数相同)

四 代码

四.1 OC模式下(ViewController.m)

#import "ViewController.h"
​
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tom;
​
@end
​
@implementation ViewController
​
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (IBAction)tomAction:(UIButton *)sender
{
    [self tomAnimationWithName:sender.currentTitle count:sender.tag];
}
- (void)tomAnimationWithName:(NSString *)name count:(NSInteger)count
{
    if([self.tom isAnimating]) return;
    NSMutableArray *arrayM=[NSMutableArray array];
    for (int i=0; i<count; i++) {
        NSString *imageName=[NSString stringWithFormat:@"%@_%02d.jpg",name,i];
        UIImage *image=[UIImage imageNamed:imageName];
        //NSString *path=[[NSBundle mainBundle] pathForResource:imageName ofType:nil];
        //UIImage *image=[UIImage imageWithContentsOfFile:path];
        [arrayM addObject:image];
    }
    //设置动画
    self.tom.animationImages=arrayM;
    //设置重复次数
    self.tom.animationRepeatCount=1;
    //设置动画时长
    self.tom.animationDuration=self.tom.animationImages.count*0.075;
    //开始动画
    [self.tom startAnimating];
    //ji结束后释放内存
    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration];
}
@end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值