#import"ViewController.h"
創(chuàng)新互聯(lián)公司長期為上千多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為牡丹企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站,牡丹網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
#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];
//設(shè)置contentSize
_huaKuang.contentSize=CGSizeMake((kuan)*4,gao);
_huaKuang.backgroundColor=[UIColorblackColor];
//設(shè)置分頁
_huaKuang.pagingEnabled=YES;
//隱藏滾動(dòng)條
//滾動(dòng)時(shí)是否顯示水平滾動(dòng)條
_huaKuang.showsHorizontalScrollIndicator=NO;
//滾動(dòng)時(shí)是否顯示垂直滾動(dòng)條
_huaKuang.showsVerticalScrollIndicator=NO;
//設(shè)置代理,需要遵循代理協(xié)議
_huaKuang.delegate=self;
//添加子視圖,因?yàn)槭嵌鄠€(gè)所以寫了一個(gè)方法來實(shí)現(xiàn)添加
[selftianJianZiShiTu];
}
-(void)tianJianZiShiTu
{
//假如有六個(gè)圖片,就要?jiǎng)?chuàng)建六個(gè)UIScrollView和六個(gè)UIImageView,并且找到六個(gè)圖片
for(int i=0;i<3;i++)
{
//創(chuàng)建UIScrollView
//為了區(qū)分開不同的照片加一個(gè)20黑邊,需要設(shè)置ScrollViewscroll View中的Left和View中的Width
UIScrollView *uisv=[[UIScrollViewalloc]initWithFrame:CGRectMake((kuan+20)*i, 0,kuan,gao)];
//把創(chuàng)建完成的添加到總的那個(gè)UIScrollView上
[_huaKuangaddSubview:uisv];
//創(chuàng)建UIImageView
UIImageView *uiiv=[[UIImageViewalloc]initWithFrame:CGRectMake(0, 0,kuan,gao)];
//把創(chuàng)建的UIImageView添加到UIScrollView中
[uisvaddSubview:uiiv];
//設(shè)置UIImageView的圖片
NSString *imageName = [NSStringstringWithFormat:@"new_feature_%d",i + 1];
uiiv.image=[UIImageimageNamed:imageName];
//設(shè)置tag值
uiiv.tag=1000;
//設(shè)置UIScrollView的代理
uisv.delegate=self;
//設(shè)置縮放范圍
uisv.minimumZoomScale=0.5;
uisv.maximumZoomScale=1.5;
//定義點(diǎn)擊事件
UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(dianJiShiJian:)];
//設(shè)置有效點(diǎn)擊數(shù)(就是雙擊)
tap.numberOfTapsRequired=2;
//添加到UIScrollView中
[uisvaddGestureRecognizer:tap];
}
}
-(void)dianJiShiJian:(UITapGestureRecognizer *)tap
{
//獲取點(diǎn)擊事件的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;
}
//滾動(dòng)結(jié)束,把所有的縮放視圖的縮放比例置為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