您的位置:首页 > 产品设计 > UI/UE

iOS复习main.storybord制作 图片浏览器 数组配合字典优化 UIImageView播放动画

2016-06-07 11:58 555 查看
#import "ViewController.h"

@interface
ViewController (){

NSMutableDictionary *imageDict;

NSMutableArray *dataArray;

}

@property (weak,nonatomic)IBOutletUIImageView
*image;

@property (weak,nonatomic)IBOutletUILabel
*describe;

@property (weak,nonatomic)IBOutletUIButton
*leftBtn;

@property (weak,nonatomic)IBOutletUIButton
*rightBtn;

@end

@implementation ViewController

- (void)viewDidLoad {

[superviewDidLoad];

NSArray *descText = [@"鲜花美酒,猫咪,圣诞快乐,卡通美女"componentsSeparatedByString:@","];

NSLog(@"%@",descText);

dataArray = [NSMutableArrayarray];

for (int i =0; i < descText.count;
i++) {

imageDict = [NSMutableDictionarydictionary];

UIImage *iimage = [UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",i+1]];

imageDict[@"image"] = iimage;

imageDict[@"icon"] = descText[i];

NSLog(@"imageDict%d:%@",i,imageDict);

// dataArray[i] = imageDict;

[dataArrayaddObject:imageDict];

}

NSLog(@"dataArray:%@",dataArray);

[selfbundle];

[selfplist];

}

static int i =1;

- (IBAction)clickedBtn:(UIButton *)sender {

NSLog(@"i = %d",i);

sender.enabled =YES;

if (i >=0 &&i<4
) {

imageDict =dataArray[i];

NSLog(@"imagDict %@",imageDict);

_describe.text =imageDict[@"icon"];

_image.image =imageDict[@"image"];

}

if (sender.tag ==0) {

_rightBtn.enabled =YES;

if (i ==0) {

sender.enabled =NO;

i =0;

}else{

i--;

sender.enabled =YES;

}

}elseif (sender.tag ==1){

_leftBtn.enabled =YES;

if (i ==3) {

sender.enabled =NO;

i =3;

}else{

i++;

sender.enabled =YES;

}

}

}

-(void)plist{

NSBundle *bundle = [NSBundlemainBundle];

//读取字典

NSString *path = [bundlepathForResource:@"myPlist.plist"ofType:nil];

NSDictionary *dictJG = [NSDictionarydictionaryWithContentsOfFile:path];

NSLog(@"dictJG %@",dictJG);

//读取数组

NSString *pathArr = [bundlepathForResource:@"myList.plist"ofType:nil];

NSArray *array = [NSArrayarrayWithContentsOfFile:pathArr];

NSLog(@"array %@",array);

}

#pragma mark -NSBudle 文件下读取图片

-(void)bundle{

//在bundle文件夹中读取图片

NSLog(@"沙盒路径:%@",NSHomeDirectory());

NSBundle *bundle = [NSBundlemainBundle];

//拼接文件路径

// NSString *path = [bundle pathForResource:@"android-themes-blue" ofType:@".png"];

NSString *path = [bundlepathForResource:@"android-themes-blue.png"ofType:nil];

_imageView.image = [UIImageimageWithContentsOfFile:path];

}

@end

UIImageView播放动画

- (IBAction)action:(id)sender {

if (_imageView.isAnimating)
return; //判断动画是否正在运行

//加载图片

NSMutableArray *imageArr = [NSMutableArray
array];

for (int i =
0; i<10; i++) {

NSString *imageName = [NSString
stringWithFormat:@"a_%d0.png",i];

// UIImage *image = [UIImage imageNamed:imageName];

//用NSBundle,优化内存

NSString *path = [[NSBundle
mainBundle] pathForResource:imageName
ofType:nil];

UIImage *image = [UIImage
imageWithContentsOfFile:path];

[imageArr addObject:image];

}

_imageView.animationImages = imageArr;

//设置动画属性

_imageView.animationDuration =
2;

_imageView.animationRepeatCount =
5;

[_imageView
startAnimating];
//开始动画

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UI界面