imageView 和 Label的用户交互默认是关闭的
注意:
图片数组中必须存放的是UIImage的对象
imageV.animationImages = photoArray ;
当重复次数设置为0时,会无限循环
imageV.animationRepeatCount = 3 ;
一定要开启动画
[imageV startAnimating] ;
一些概念:
1.frame bounds center之间的联系与区别:
它们的共同点都是结构体
frame(CGRect):它描述的是子视图在父视图中的位置和大小
bounds(CGRect):它描述的是视图在自身坐标系中的位置和大小(0,0)
center(CGPoint):它描述的是子视图在父视图中的位置
2. 什么是定时器?
它是NSTimer的对象,它的作用是间隔某一段时间调用某一个方法
第一个参数 间隔的时间
第二个参数 目标对象
第三个参数 方法(注意如果方法携带参数,那么这个参数就是NSTimer对象)
第四个参数 携带的参数
第五个参数 是否重复调用
NSTime *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(XXXX:) userInfo:@"提百万" repeats:YES];
(1)暂停定时器
[timer setFireDate:[NSDate distantFuture]];
(2)重启定时器
timer.fireDate = [NSDate distantPast];
3.UIImageView用于显示图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 40, 200, 300)];
imageView.image = [UIImage imageNamed:@"angry_00.jpg"];
4.如果要在imageView上添加按钮,必须保证用户交互是打开的
imageView.userInteractionEnabled = YES;
5.强制剪切 减掉超出父视图的部分
imageView.layer.masksToBounds = YES;
imageView.clipsToBounds = YES;
6.将将绿色标签置于最底层:
[self.view sendSubviewToBack:greenLabel];
将绿色标签提到最上层:
[self.view bringSubviewToFront:greenLabel];
交换两个层级:
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:2];
7.UIView动画,它是通过改变控件的位置和大小以及颜色来实现的
第一种方式:
告诉系统要准备开始播放动画
[UIView beginAnimations:nil context:nil];
设置动画的播放时间
[UIView setAnimationDuration:2.0];
设置动画的重复次数
[UIView setAnimationRepeatCount:2.0];
设置动画延迟播放的时间
[UIView setAnimationDelay:2.0];
提交动画
[UIView commitAnimations];
第二种方式:
第一个参数是动画播放时间
[UIView animateWithDuration:2.0 animations:^{
backView.frame = CGRectMake(300, 300, 100, 100);
backView.backgroundColor = [UIColor redColor];
}] ;
或
[UIView animateWithDuration:2.0 animations:^{
backView.frame = CGRectMake(300, 300, 100, 100);
backView.backgroundColor = [UIColor redColor];
} completion:^(BOOL finished) {
NSLog(@"已结束");
}] ;