| 
 
| 本帖最后由 chingwei2011 于 2015-10-12 20:42 编辑 
 一共四张素材图片,都见切成 同样大小 440*570
 
     1.首先将图片文件夹放入到project中,并如图所示,选中一张作为imageView的封面
 2.添加按钮事件和imgaeview的事件,
 3.代码如下。是黑马老师的代码。我照办过来的。
 
 复制代码#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *cartonImgView;
@end
@implementation ViewController
- (IBAction)showPicAct:(id)sender {
    
    //把所有图片都加到集合中
    NSMutableArray *imgs =[[NSMutableArray alloc] init];
    
    
    //把所有的图片都加载至内存中
    for(int i=1 ;i <= 4 ;i++){
        
        NSString *imgName =[NSString stringWithFormat:@"carton%02d.jpeg",i];
    //获取图片对象
        UIImage *img =[UIImage imageNamed:imgName];
        
        [imgs addObject:img];
    }
    
    //给图片设定动画
    self.cartonImgView.animationImages=imgs;
    //_cartonImgView.animationImages=imgs;
    
    //设定动画时长
    _cartonImgView.animationDuration=imgs.count*1;
    
    //重复次数
    _cartonImgView.animationRepeatCount = 1 ;
    
    //播放动画
    [_cartonImgView startAnimating];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
跟着黑马老师边学边敲的代码,觉得这个比较有趣,他上两个课时讲的是发短信打电话和切换屏,这几个例子让我们对ios项目有了大概的了解。非常感谢。
 
 
 
 
 | 
 |