UISCrollView内部放大
//
// ScrollViewController.m
// MyScrollView
//
// Created by lanou on 12-12-20.
// Copyright (c) 2012年 lanou. All rights reserved.
//
#import "ScrollViewController.h"
@interfaceScrollViewController ()
@end
@implementation ScrollViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
returnself;
}
- (void)viewDidLoad
{
[superviewDidLoad];
_s = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,320,480)];
_s.contentSize = CGSizeMake(320*5,480);
_s.delegate = self;
_s.scrollsToTop = YES;//点下title ScrollView自动滑
_s.pagingEnabled = YES;//一次滑动一个ScrollView的长或宽
_s.bounces = NO;//边界可超出单自动缩回
_s.minimumZoomScale = 2;
_s.maximumZoomScale = 1;
[self.viewaddSubview:_s];
for (int i=0; i<5; i++)
{
[self addGallery:i];
}
//pageControl控件
_pageControl = [[UIPageControlalloc]initWithFrame:CGRectMake(100, 500, 120, 20)];
_pageControl.numberOfPages = 4;
_pageControl.pageIndicatorTintColor = [UIColorredColor];
_pageControl.currentPageIndicatorTintColor = [UIColorblueColor];
[_pageControladdTarget:selfaction:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
[self.viewaddSubview:_pageControl];
}
-(void)addGallery:(int)i
{
UIScrollView *scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(320*i, 0, 320, 480)];
scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 2;
// scrollView.contentSize = CGSizeMake(320, 480);
scrollView.delegate = self;
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
if (i<4)
{
NSString *pName = [NSStringstringWithFormat:@"p%d.jpg",i+1];
imageView.image = [UIImage imageNamed:pName];
}
else if(i==4)
{
NSMutableArray *images = [NSMutableArrayarrayWithCapacity:1];
for (int i=1; i<8; i++)
{
NSString *name = [NSString stringWithFormat:@"huoju_%d.tiff",i];
UIImage *image = [UIImage imageNamed:name];
[images addObject:image];
}
imageView.animationImages = images;
imageView.animationDuration = 1.0;
[imageView startAnimating];
[scrollView addSubview:imageView];
}
[scrollView addSubview:imageView];
[_s addSubview:scrollView];
[scrollView release];
[imageView release];
}
-(void)pageChanged:(UIPageControl *)pc
{
int page = pc.currentPage;
[_sscrollRectToVisible:CGRectMake(320*page, 50, 320, 350) animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) /pageWidth) +1;
NSLog(@"%d",page);
_pageControl.currentPage = page;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView.subviews objectAtIndex:0];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end