iOS-OC之相册,可以放大,不能循环查看
#import"ViewController.h"
创新互联公司长期为上千多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为牡丹企业提供专业的网站设计、成都做网站,牡丹网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
#define kuan [UIScreen mainScreen].bounds.size.width
#define gao [UIScreen mainScreen].bounds.size.height
@interfaceViewController ()
@property (weak,nonatomic)IBOutletUIScrollView *huaKuang;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//设置contentSize
_huaKuang.contentSize=CGSizeMake((kuan)*4,gao);
_huaKuang.backgroundColor=[UIColorblackColor];
//设置分页
_huaKuang.pagingEnabled=YES;
//隐藏滚动条
//滚动时是否显示水平滚动条
_huaKuang.showsHorizontalScrollIndicator=NO;
//滚动时是否显示垂直滚动条
_huaKuang.showsVerticalScrollIndicator=NO;
//设置代理,需要遵循代理协议
_huaKuang.delegate=self;
//添加子视图,因为是多个所以写了一个方法来实现添加
[selftianJianZiShiTu];
}
-(void)tianJianZiShiTu
{
//假如有六个图片,就要创建六个UIScrollView和六个UIImageView,并且找到六个图片
for(int i=0;i<3;i++)
{
//创建UIScrollView
//为了区分开不同的照片加一个20黑边,需要设置ScrollViewscroll View中的Left和View中的Width
UIScrollView *uisv=[[UIScrollViewalloc]initWithFrame:CGRectMake((kuan+20)*i, 0,kuan,gao)];
//把创建完成的添加到总的那个UIScrollView上
[_huaKuangaddSubview:uisv];
//创建UIImageView
UIImageView *uiiv=[[UIImageViewalloc]initWithFrame:CGRectMake(0, 0,kuan,gao)];
//把创建的UIImageView添加到UIScrollView中
[uisvaddSubview:uiiv];
//设置UIImageView的图片
NSString *imageName = [NSStringstringWithFormat:@"new_feature_%d",i + 1];
uiiv.image=[UIImageimageNamed:imageName];
//设置tag值
uiiv.tag=1000;
//设置UIScrollView的代理
uisv.delegate=self;
//设置缩放范围
uisv.minimumZoomScale=0.5;
uisv.maximumZoomScale=1.5;
//定义点击事件
UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(dianJiShiJian:)];
//设置有效点击数(就是双击)
tap.numberOfTapsRequired=2;
//添加到UIScrollView中
[uisvaddGestureRecognizer:tap];
}
}
-(void)dianJiShiJian:(UITapGestureRecognizer *)tap
{
//获取点击事件的view
UIScrollView *uisv1=(UIScrollView *)tap.view;
if(uisv1.zoomScale!=1.0)
{
[uisv1setZoomScale:1.0animated:YES];
return ;
}
CGPoint location=[taplocationInView:tap.view];
CGRect rect=CGRectMake(location.x-100, location.y-100, 200, 200);
[uisv1zoomToRect:rectanimated:YES];
}
//指定缩放的视图
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
if (scrollView ==_huaKuang) {
returnnil;
}
UIImageView *imageView = (UIImageView *)[scrollViewviewWithTag:1000];
return imageView;
}
//滚动结束,把所有的缩放视图的缩放比例置为1.0
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
if (scrollView ==_huaKuang) {
for (id objin_huaKuang.subviews) {
if ([objisKindOfClass:[UIScrollViewclass]]) {
UIScrollView *scaleSC = (UIScrollView *)obj;
scaleSC.zoomScale = 1.0;
}
}
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
本文标题:iOS-OC之相册,可以放大,不能循环查看
本文网址:http://pwwzsj.com/article/jdpdoe.html