UIday0603:UIImageView的属性和用法 Tom猫举例
2015-08-31 21:39
441 查看
UIImageView常⽤用属性
image //设置图⽚
animationImages //设置⼀组动态图片
animationDuration //设置播放一次一组动态图片的时间
animationRepeatCount //设置重复次数
startAnimating //开始动画
stopAnimating //结束动画
UIImageView相当于一个相框,可以存放一个或一组图片 UIImage 是图片对象
AppDelegate.m
RootViewController.m
RootView.h
RootView.m
image //设置图⽚
animationImages //设置⼀组动态图片
animationDuration //设置播放一次一组动态图片的时间
animationRepeatCount //设置重复次数
startAnimating //开始动画
stopAnimating //结束动画
UIImageView相当于一个相框,可以存放一个或一组图片 UIImage 是图片对象
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; RootViewController * rootVC = [[RootViewController alloc]init]; self.window.rootViewController = rootVC; return YES; }
RootViewController.m
#import "RootViewController.h" @interface RootViewController () @property(nonatomic,strong)RootView * rv; @end @implementation RootViewController -(void)loadView{ self.rv = [[RootView alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.view = _rv; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // 设置初始背景图片 self.rv.imageView.image = [UIImage imageNamed:@"cat_angry0000.jpg"]; // 添加eatButton点击事件 [self.rv.eatButton addTarget:self action:@selector(eatButtonAction:) forControlEvents:UIControlEventTouchUpInside]; // 添加knockOutButton:点击事件 [self.rv.knockOutButton addTarget:self action:@selector(knockOutButton:) forControlEvents:UIControlEventTouchUpInside]; } -(void)eatButtonAction:(UIButton *)sender{ [self p_ImageViewAnimationWithName:@"cat_eat" count:40 duration:0.08]; } -(void)knockOutButton:(UIButton *)sender{ [self p_ImageViewAnimationWithName:@"cat_knockout" count:81 duration:0.08]; } //私有方法:播放 -(void)p_ImageViewAnimationWithName:(NSString *)name count:(NSInteger)count duration:(NSTimeInterval)time{ if (![self.rv.imageView isAnimating] && ![name isEqualToString:@"cat_listen"]) { NSMutableArray * tempArray = [NSMutableArray array]; // 拼接图片 并将图片名字放入数组 for (int i=0 ; i<count; i++) { NSString * s = [NSString stringWithFormat:@"%@%04d.jpg",name,i]; UIImage * image = [UIImage imageNamed:s]; [tempArray addObject:image]; } // 给animationImages 数组赋值 self.rv.imageView.animationImages = tempArray; // 播放时间 self.rv.imageView.animationDuration = count * time; // 播放次数 self.rv.imageView.animationRepeatCount = 1; // 播放动画 [self.rv.imageView startAnimating]; }else{ NSMutableArray * tempArray = [NSMutableArray array]; // 拼接图片 并将图片名字放入数组 NSString * s = [NSString stringWithFormat:@"cat_listen.jpg"]; UIImage * image = [UIImage imageNamed:s]; [tempArray addObject:image]; // 给animationImages 数组赋值 self.rv.imageView.animationImages = tempArray; // 播放时间 self.rv.imageView.animationDuration = 1; // 播放次数 self.rv.imageView.animationRepeatCount = 1; // 播放动画 [self.rv.imageView startAnimating]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
RootView.h
#import <UIKit/UIKit.h> @interface RootView : UIView @property(nonatomic,strong)UIImageView * imageView; @property(nonatomic,strong)UIButton * eatButton; @property(nonatomic,strong)UIButton * knockOutButton; @end
RootView.m
#import "RootView.h" @implementation RootView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self p_setupViews]; } return self; } // 布局 -(void)p_setupViews{ self.backgroundColor = [UIColor yellowColor]; // 设置图片大小和RootView一样大 self.imageView = [[UIImageView alloc]initWithFrame:self.bounds]; self.imageView.backgroundColor = [UIColor grayColor]; [self addSubview:_imageView]; //添加上eatButton self.eatButton = [UIButton buttonWithType:UIButtonTypeSystem]; self.eatButton.frame = CGRectMake(50, 50, 50, 50); self.eatButton.backgroundColor = [UIColor blueColor]; [self addSubview:_eatButton]; // self.knockOutButton = [UIButton buttonWithType:UIButtonTypeSystem]; self.knockOutButton.frame = CGRectMake(100, 150, 180, 180); self.knockOutButton.backgroundColor = [UIColor clearColor]; [self addSubview:_knockOutButton]; } @end
相关文章推荐
- EasyUI——常见用法总结
- eightQueen1.0
- UIday0602:UISlider(滑块控件)的属性和用法
- iOS --- 使用GPUImage实现的简单滤镜效果
- Building a RESTful Web Service
- iOS开发学习之UIScrollerView实现新特性
- iOS-UI基础-02加法计算器
- iOS开发 ----- UI生命周期
- iOS开发 ----- UILable
- UIday0601:UISegmentedControl的属性和用法
- 基于MVC4+EasyUI的Web开发框架经验总结(4)--使用图表控件Highcharts
- iOS-UI基础-01简介
- GUI
- IOS关于UITabBarController的使用
- iOS:UIButton按钮的详解
- 自制Qt Quick场景切换管理类
- Version xx of the JVM is not suitable for this product
- 如何使用UIAutomation进行iOS 自动化测试(Part II)
- UITextFielddelegate委托方法注释
- UINavigationController 、界面通信