UIScrollView滾動視圖2 // // Created by 非凡程序員 on 16/7/1. // Copyright © 2016年 gg. All rights reserved. //程序員
#import "ViewController.h".net
@interface ViewController ()code
@endorm
@implementation ViewController int a=0;get
// //縮放string
// _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 375, 657)]; // _scrollView.backgroundColor=[UIColor grayColor]; // _scrollView.contentSize=CGSizeMake(700, 471); // [self.view addSubview:_scrollView]; //
// _imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 700, 471)]; // _imageView.image=[UIImage imageNamed:@"白鳳.jpeg"]; //// [self.view addSubview:_imageView]; // [_scrollView addSubview:_imageView]; // _scrollView.delegate=self; // _scrollView.contentSize=_imageView.frame.size; //
// //縮放 // _scrollView.maximumZoomScale=3; // _scrollView.minimumZoomScale=0.1;it
//添加計時器循環 [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scroll) userInfo:nil repeats:YES]; _page=[[UIScrollView alloc]initWithFrame:CGRectMake(42.5, 50, 280, 170)];
// _page.backgroundColor=[UIColor yellowColor];io
_page.contentSize=CGSizeMake(280*37, 150); _page.pagingEnabled=YES; _page.delegate = self; [self.view addSubview:_page]; for (int i=0; i<37; i++) { UIImageView *view=[[UIImageView alloc]initWithFrame:CGRectMake(280*i, 0, 280, 150)];
// [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(scroll) userInfo:nil repeats:YES]; view.image=[UIImage imageNamed:[NSString stringWithFormat:@"%02i.tiff",i+1]];import
[_page addSubview:view]; } _page.delegate=self; [self.view addSubview:_page]; [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(tutu) userInfo:nil repeats:YES]; _tusiji=[[UIScrollView alloc]initWithFrame:CGRectMake(42.5, 250, 155, 90)];
// _tusiji.backgroundColor=[UIColor yellowColor];select
_tusiji.contentSize=CGSizeMake(155*20, 90); _tusiji.pagingEnabled=YES; _tusiji.delegate = self; [self.view addSubview:_tusiji]; for (int i=0; i<20; i++) { UIImageView *view=[[UIImageView alloc]initWithFrame:CGRectMake(155*i, 0, 155, 90)]; // [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(scroll) userInfo:nil repeats:YES]; view.image=[UIImage imageNamed:[NSString stringWithFormat:@"兔斯基雙人-%02i(被拖移).tiff",i+1]]; [_tusiji addSubview:view]; } _tusiji.delegate=self; [self.view addSubview:_tusiji]; //滾動條是否顯示 //水平 _page.showsHorizontalScrollIndicator=YES; //垂直 _page.showsVerticalScrollIndicator=NO; //分頁控制器 _control=[[UIPageControl alloc]initWithFrame:CGRectMake(280, 50, 280, 150)]; //數量 _control.numberOfPages=5; //當前頁 _control.currentPage=0; //當前顏色 _control.currentPageIndicatorTintColor=[UIColor redColor]; //普通顏色 _control.pageIndicatorTintColor=[UIColor orangeColor];
// [_page addSubview:_control];
} -(void)scrollViewDidScroll:(UIScrollView )scrollView { _control.currentPage=_page.contentOffset.x/_page.frame.size.width; } -(void)scroll { _page.contentOffset=CGPointMake(280a, 0); a++; if (a==37) { a=0; } } -(void)tutu { _tusiji.contentOffset=CGPointMake(155*a, 0); a++; if (a==20) { a=0; } }
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return _imageView; }
@end