UIScrollView的属性总结
|
iOS UIScrollView中实现分页滚动----例子为2张图片的效果
UIImage *image1=[UIImage imageNamed:@"1.png"];
UIImage *image2=[UIImage imageNamed:@"2.png"];
imgArray=[[NSArray alloc]initWithObjects:image1,image2, nil];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
for (int i=0; i<[imgArray count]; i++) {
img=[[UIImageView alloc]initWithImage:[imgArray objectAtIndex:i]];
[self.scrollView addSubview:img];
[img setFrame:CGRectMake(320*i, 0, 320, 460)];
}
[scrollView setBackgroundColor:[UIColor grayColor]];
scrollView.contentSize=CGSizeMake(scrollView.frame.size.width*[imgArray count], 460);
scrollView.scrollEnabled=YES;
scrollView.pagingEnabled=YES;
//scrollView.minimumZoomScale=0.1;
//scrollView.maximumZoomScale=2.0;
scrollView.showsHorizontalScrollIndicator=YES;//横向显示滚动条
scrollView.showsVerticalScrollIndicator=NO;
scrollView.bounces=NO; //反弹效果
scrollView.alwaysBounceVertical=YES;
scrollView.alwaysBounceHorizontal=YES;
//scrollView.delegate=self;
[self.view addSubview:scrollView];
定时滚动分页----例子为2张图片的效果
在ViewDidLoad中添加NSTimer
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(changePic) userInfo:nil repeats:YES];
changePin实现
-(void)changePic
{
if (currentPositon==0) {
currentPositon++;
}else if(currentPositon==[imgArray count]){
currentPositon=0;
}
[scrollView setContentOffset:CGPointMake(320*currentPositon, 0) animated:YES];
currentPositon++;
}