IOS开发 照片墙案例

本节学习内容:

1.照片墙的基本概念

2.照片墙的实现原理

3.照片墙的实现方法


IOS开发 照片墙案例_第1张图片
案例

1.创建丙个视图控器分别为VCRoot,VCImageShow 都继承于UIViewController

【VCRoot,m】

#import"VCRoot.h"

#import"VCImageShow.h"

@interface VCRoot()

@end

@implementation VCRoot

-(void)viewDidLoad{

[super viewDidLoad];

self.title=@"照片墙";

self.navigationController.navgationBar.barTintColor=[UIColor purpleColor];

//使用导航栏不透明

self.navigationController.navigationBar.translucent=NO;

UIScrollView* sv=[[UIScrollView alloc]init];

//设置位置大小

sv.frame=CGRectMake(10,10,300,480);

//设置画布大小

sv.contentSize=CGSizeMake(300,480*1.5);

sv.showsVerticalScrollIndicator=NO;

//打开交互事件

sv.userInteractionEnabled=YES;

self.view.backgroundColor=[UIColor whiteColor];

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

NSString* strName=[NSString stringWithFormat:"@17_%d.jpg",i+1];

UIImage* image=[UIImage imageNamed:strName];

UIImageView* iView=[[UIImageView alloc]initWithImage:image];

iView.grame=CGRectMake(3+(I%3)*100,(i/3)*140+10,90,130);

[sv addSubview:iView];

//开启交互模式

iView.userInteractionEnabled=YES;

//创建点击手势

UITapGestureRecognizer* tap=[[UITapGestureRecongnizer alloc]initWithTarget:self action:@selector(pressTap:)];

//单次点击

tap.numberOftapsReuired=1

//单个手指

tap.numberOfTouchsRequired=1

[iView addGestureRecognizer:tap];

//图像对像的tag值

iView.tag=101+i;

}

[self.view addSubview:sv];

}

方法三 tag值

-(void)pressTap:(UITapGesttureRecongnizer*)tap{

UIImageView* imageView=[UIImageView*)tap.view;

VCImageShow* imageShow=[[VCImageShow alloc]init];

imageShow.imageTag=imageView.tag;

[self.navigationController pushViewController:imageShow animated:YES];

}


/*方法二

-(void)pressTap:(UITapGestureRecognizer*)tap{

UIImageView* imageView=(UIImageView*)tap.view;

//创建视图控制器

VCImageShow* imageShow=[[VCImageShow alloc]init];

//点击的图像视图赋值

//imageShow.imageView=imageView;修改为

imageShow.image=imageView.image;

//将控制器推出

[self.navigationController pushViewController:imageShow animated:YES];

}

*/

【VCImageShow.h】

#import

@interface VCImageShow:UIViewController

//图像视图的tag

@property(nonatomic,assign)NSUIngeger imageTag;

//图像对象

@property(nonatomic,retain)UITmage* image;

//图像视图对象

@property(noatomic,retain)UIImageView* imageView;

【VCImageShow.m】

#import"VCImageShow"

@imterface VCImageShow()

@end

@implementation VCImageShow

-(void)viewDidLoad{

[super viewDidLoad];

self.title=@"图片展示";

_imageView=[[UIImageView alloc]init;

_imageView.frame=CGRectMake(0,0,320,480);

//方法二

//_imageView.image=_image;

//方法三

_imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"17_%lu.jpg",_imageTag_100]];

//一个视图对象只能有一个根视图,分我们把视图添加到新的父视图上时,从原因的父视图中给删除掉

[self.view addSubview:_imageView];

}


【AppDelegate.m】

#import"AppDelegate.h"

#import"VCRooth"

@interface AppDelegate()

@end

@implementation AppDelegate

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

//导航控器框架结果

self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

UINavigationController* nav=[[UINavigationController alloc]]initWithRootViewController:[VCRoot alloc]init];

self.window.rootViewConroller=nav;

return YES;

}

你可能感兴趣的:(IOS开发 照片墙案例)