主要代码

RootView.h

#import <UIKit/UIKit.h>@interface RootView : UIView//定义大的 scrollView---它的上面需要放置8个 ImageScrollView
@property(nonatomic,strong)UIScrollView *mainScrollView;//定义一个数组(存放8个 ImageScrollView)
@property(nonatomic,strong)NSMutableArray *array;@end

RootView.m

#import "RootView.h"
#import "ImageScrollView.h"
#define k_screenWidth [UIScreen mainScreen].bounds.size.width
#define k_screenHeight [UIScreen mainScreen].bounds.size.height@implementation RootView- (instancetype)initWithFrame:(CGRect)frame
{self = [super initWithFrame:frame];if (self) {[self createMainScrollView];[self createEightImageScrollView];}return self;
}#pragma mark 创建mainScrollView
-(void)createMainScrollView{self.mainScrollView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];//设置 contentSizeself.mainScrollView.contentSize = CGSizeMake(8 * k_screenWidth, 0);//整页翻动self.mainScrollView.pagingEnabled = YES;[self addSubview:self.mainScrollView];}#pragma mark 创建8个小的 imageScrollView
-(void)createEightImageScrollView{for (int i = 0; i < 8; i++) {//图片的名字 --注意 i+1NSString *name = [NSString stringWithFormat:@"h%d.jpeg",i + 1];ImageScrollView *smallScroll = [[ImageScrollView alloc]initWithFrame:CGRectMake(i * k_screenWidth, 0, k_screenWidth, k_screenHeight) withImageName:name];//设置最大的放大比例smallScroll.maximumZoomScale = 2.0f;//设置最小的缩放比例smallScroll.minimumZoomScale = 0.5f;[self.mainScrollView addSubview:smallScroll];//不可以使用_array[self.array addObject:smallScroll];}
}#pragma mark 重写 @property(nonatomic,strong)NSMutableArray *array 的   getter 方法// 懒加载 ---可以在一定程度上缓解内存问题(什么时候使用,什么时候创建)
-(NSMutableArray *)array{if (_array == nil) {_array = [NSMutableArray array];}return _array;
}@end

RootViewController.m

//
//  RootViewController.m
//  UI_lesson7_photo
//
//  Created by lanou3g on 15/10/30.
//  Copyright (c) 2015年 lirui. All rights reserved.
//#import "RootViewController.h"
#import "RootView.h"
#import "ImageScrollView.h"@interface RootViewController ()<UIScrollViewDelegate>
@property(nonatomic,strong)RootView *rootView;
//用来记录,被缩放的小ImageScrollView
@property(nonatomic,strong)ImageScrollView *selectScroll;
@end@implementation RootViewController-(void)loadView{self.rootView = [[RootView alloc]initWithFrame:[UIScreen mainScreen].bounds];self.view = self.rootView;
}- (void)viewDidLoad {[super viewDidLoad];//设置 mainScrollView 的 代理self.rootView.mainScrollView.delegate = self;//设置 8个小的 imageScrollView 的代理for (ImageScrollView *temp in self.rootView.array) {temp.delegate = self;}//缩放功能的实现 (UIScrollView 自带的缩放功能)//1.需要通过属性设置放大和缩小的 倍数//2.通过代理告诉操作系统,你需要缩放的控件 (UIScrollView 上面的控件)}#pragma mark 缩放的控件
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{if (scrollView != self.rootView.mainScrollView) {ImageScrollView *imageScroll = (ImageScrollView *)scrollView;return imageScroll.displayImageView;}return nil;
}#pragma mark 结束减速的时候
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{if (scrollView == self.rootView.mainScrollView) {NSInteger index = scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width;ImageScrollView *currentShowScroll = self.rootView.array[index];if (currentShowScroll != self.selectScroll) {[self.selectScroll setZoomScale:1.0f animated:YES];CGPoint center ;center.x = [UIScreen mainScreen].bounds.size.width / 2;center.y = [UIScreen mainScreen].bounds.size.height / 2;// 每次缩小之后重新设置 scrollView 的中心点self.selectScroll.displayImageView.center = center;}}
}#pragma mark 进行缩放的时候会执行的方法(不管缩放多大的比例)
-(void)scrollViewDidZoom:(UIScrollView *)scrollView{if (scrollView != self.rootView.mainScrollView) {self.selectScroll = (ImageScrollView *)scrollView;//  zoomScale 默认尺度if(scrollView.zoomScale < 1.0){CGPoint center ;center.x = [UIScreen mainScreen].bounds.size.width / 2;center.y = [UIScreen mainScreen].bounds.size.height / 2;//每次缩小之后重新设置 图片 的中心点self.selectScroll.displayImageView.center = center;}}}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}/*
#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller.
}
*/@end

ImageScrollView.h

#import <UIKit/UIKit.h>@interface ImageScrollView : UIScrollView//1.定义 UIImageView
@property(nonatomic,strong)UIImageView *displayImageView;#pragma mark 自定义初始化方法
-(instancetype)initWithFrame:(CGRect)frame withImageName:(NSString *)name;@end

ImageScrollView.m

#import "ImageScrollView.h"@implementation ImageScrollView#pragma mark 自定义初始化方法
-(instancetype)initWithFrame:(CGRect)frame withImageName:(NSString *)name{self = [super initWithFrame:frame];if (self) {[self createdisplayImageView:name];}return self;
}#pragma mark 创建 displayImageView 的方法
-(void)createdisplayImageView:(NSString *)name  {self.displayImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:name]];//(*)设置 displayImageView 的 frameself.displayImageView.frame = self.bounds;[self addSubview:self.displayImageView];}@end

AppDelegate.m

//
//  AppDelegate.m
//  UI_lesson7_photo
//
//  Created by lanou3g on 15/10/30.
//  Copyright (c) 2015年 lirui. All rights reserved.
//#import "AppDelegate.h"
#import "RootViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyAndVisible];RootViewController *rootVC = [[RootViewController alloc]init];self.window.rootViewController = rootVC;return YES;
}- (void)applicationWillResignActive:(UIApplication *)application {// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}- (void)applicationDidEnterBackground:(UIApplication *)application {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}- (void)applicationWillEnterForeground:(UIApplication *)application {// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}- (void)applicationDidBecomeActive:(UIApplication *)application {// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}@end

在工程里需要添加图片,图片名尽量按照规律顺序命名,方便使用循环加载,此demo添加了8张图片,h1.jpeg---h8.jpeg

实现了 放大,缩小,翻页等基本效果,照片展示与屏幕等大。

UIdemo 制作一个简单的iPhone相册相关推荐

  1. 如何使用cocos2d-x 3.0来做一个简单的iphone游戏教程(第一部分)

    游戏截图: cocos2d-x 是一个支持多平台的开源框架,用于构建游戏.应用程序和其他图形界面交互应用.Cocos2d-x项目可以很容易地建立和运行在iOS,Android的三星Bada,黑莓Bla ...

  2. (译)如何使用GameCenter制作一个简单的多人游戏教程:第一部分

    免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切勿进行商业传播.同时,转载时不要移除本申明.如产生任何纠纷,均与本博客所有人.发表该翻译稿之人无任何关系.谢谢合作 ...

  3. html5 iphone菜单栏,如何制作一个HTML5的iPhone应用程序

    在过去的一年里,你不是很容易踩踏,对于所有的使用Objective-C开发iPhone程序的开发者而言,日子都不那么好过,你不是为了学习开发iPhone应用程序曾经硬着头皮去读着那生涩难懂的学习教程, ...

  4. 使用 Flutter 制作一个简单的笑话生成器应用程序

    在本教程中,我将向您展示如何使用 Flutter 制作一个简单的笑话生成器应用程序 对于这个项目,我们将从 RESTful API 获取数据 API的链接: 随机笑话 对于这个项目,我不会关注应用程序 ...

  5. 实例学习SSIS(一)--制作一个简单的ETL包

    http://www.cnblogs.com/tenghoo/archive/2009/10/archive/2009/10/archive/2009/10/16/ssis_lookup.html 导 ...

  6. python计算器教程,用Python程序制作一个简单的计算器

    用Python程序制作一个简单的计算器 在此示例中,您将学习创建一个简单的计算器,该计算器可以根据用户的输入进行加,减,乘或除. 要理解此示例,您应该了解以下Python编程主题: 通过函数创建简单计 ...

  7. 32位mips运算器logisim_大神教你制作一个简单的16位CPU

    如何制作一个简单的16位CPU,首先我们要明确CPU是做什么的,想必各位都比我清楚,百度的资料也很全..... 如果想要制作一个CPU,首先得明白下计算机的组成结构(或者计算机的替代品,因为并不是只有 ...

  8. 数字信号 fft c源码_如何制作一个简单的人体动态识别微信小程序(附源码)

    知乎小白第一次写专栏,还请多指教. 先放成果. GitHub源码: lrioxh/HAR-applet-of-Wechat​github.com b站演示视频: 居然不需要服务器?!如何制作一个简单的 ...

  9. 用计算机制作动画,如何使用制作工具制作一个简单的Flash动画-电脑自学网

    怎么制作Flash动画?通过Adobe Flash我们可以制作出非常有趣好看的动画,也可以制作一键简单的小动画,下面给大家介绍如何使用制作工具制作一个简单的Flash动画. 操作方法: 1.打开fla ...

最新文章

  1. 浅谈JavaScript作用域,关于Java的学习路线资料
  2. Golang的值类型和引用类型的范围、存储区域、区别
  3. mysql xdevapi_MySql Connector/C++8简介
  4. php中mysqli 处理查询结果集的几个方法
  5. nginx 配置路由
  6. php期末考试题机考_phP基础知识期末考试题.doc
  7. [转载] python将int转为string_python – 在Pandas中将列名从int转换为string
  8. python创建gui界面_你要的 Python 创建 GUI 用户界面程序,来咯
  9. 里诺合同管理合同上传步骤_客户关系管理:合同
  10. 网站 小图标 大全 url
  11. Lua 程序设计——Lua 教程01
  12. 【论文笔记】气道树分割:A 3D UNet-Graph Neural Network for Airway Segmentation
  13. 云原生-备份(原文地址:https://www.infoq.cn/article/fA42rfjV*dYGAvRANFqE)
  14. linux服务器怎么做快照,云服务器怎么创建快照
  15. 输入一个字符串,将其逆序输出。
  16. 技术一般的程序员找工作,如今真的一年比一年难...
  17. caxa电子图板2022软件
  18. AD620仪表放大器介绍
  19. 如何理解路由器的包转发率
  20. EW简单设置代理web服务器

热门文章

  1. 什么是web前端技术?要学什么?
  2. Microsoft (Office) 365本地无法激活解决方案
  3. 区块链 - 牵一发而动全身的链式结构
  4. Job for tomcat.service failed because the control process exited with error code 解决办法:
  5. 基于Paddlehub实现的秒换证件照底色
  6. DAVINCI DM365-DM368开发攻略—U-boot-2010.12-rc2-psp03.01.01.39及UBL的移植 .
  7. IOS积分墙:末落贵族与新兴势力PK
  8. MATLAB解隐函数方程时符号表达式转化为数值的方法-用vpa函数
  9. 杨辉三角(Python-动态规划)
  10. [大数据文章之其一] 大数据对你来说意味着什么?