建了一个主ScrollView
然后建了三个子ScrollView 加载在主ScrollView上, 如何实现多图缩放呢,,,我发的这个方法只能实现第一个图片的缩放
#import "MainViewController.h"
@interface MainViewController ()<UIScrollViewDelegate>@property (nonatomic, retain) UIScrollView *myscroll1;
@property (nonatomic, retain) UIScrollView *myscroll2;
@property (nonatomic, retain) UIScrollView *myscroll3;@end@implementation MainViewController-(void)dealloc
{
[_myscroll1 release];
[_myscroll2 release];
[_myscroll3 release];
[super dealloc];
}- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//主scrollView
UIScrollView *myscroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
myscroll.backgroundColor = [UIColor yellowColor];
[self.view addSubview:myscroll];
[myscroll release];
myscroll.contentSize = CGSizeMake(3 * 375, 667);
myscroll.pagingEnabled = YES;
//第一个scrollView
self.myscroll1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
self.myscroll1.backgroundColor = [UIColor redColor];
[myscroll addSubview:self.myscroll1];
self.myscroll1.maximumZoomScale = 2.0;
self.myscroll1.minimumZoomScale = 0.5;
self.myscroll1.delegate = self;
[self.myscroll1 release];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
imageView1.image = [UIImage imageNamed:@"0.jpg"];
[self.myscroll1 addSubview:imageView1];
[imageView1 release];
//第二个scrollView
self.myscroll2 = [[UIScrollView alloc] initWithFrame:CGRectMake(375, 0, 375, 667)];
self.myscroll2.backgroundColor = [UIColor redColor];
[myscroll addSubview:self.myscroll2];
self.myscroll2.maximumZoomScale = 2.0;
self.myscroll2.minimumZoomScale = 0.5;
self.myscroll2.delegate = self;
[self.myscroll2 release];
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
imageView2.image = [UIImage imageNamed:@"1.jpg"];
[self.myscroll2 addSubview:imageView2];
[imageView2 release];
//第二个scrollView
self.myscroll3 = [[UIScrollView alloc] initWithFrame:CGRectMake(750, 0, 375, 667)];
self.myscroll3.backgroundColor = [UIColor redColor];
[myscroll addSubview:self.myscroll3];
self.myscroll3.maximumZoomScale = 2.0;
self.myscroll3.minimumZoomScale = 0.5;
self.myscroll3.delegate = self;
[self.myscroll3 release];
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
imageView3.image = [UIImage imageNamed:@"2.jpg"];
[self.myscroll3 addSubview:imageView3];
[imageView3 release];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
//缩放scrollView
//2.指定一个scrollView的子视图,跟着scrollView放大缩小
//有两点需要注意的
//1.scrollView放大缩小之后,contentSize会和子视图frame的size一样大
//2.scrollView的滚动条也是两个视图,都是UIImageView,会始终处在显示的最上面(也就是子视图数组的最后面 )
return [self.myscroll1.subviews firstObject];
}
然后建了三个子ScrollView 加载在主ScrollView上, 如何实现多图缩放呢,,,我发的这个方法只能实现第一个图片的缩放
#import "MainViewController.h"
@interface MainViewController ()<UIScrollViewDelegate>@property (nonatomic, retain) UIScrollView *myscroll1;
@property (nonatomic, retain) UIScrollView *myscroll2;
@property (nonatomic, retain) UIScrollView *myscroll3;@end@implementation MainViewController-(void)dealloc
{
[_myscroll1 release];
[_myscroll2 release];
[_myscroll3 release];
[super dealloc];
}- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//主scrollView
UIScrollView *myscroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
myscroll.backgroundColor = [UIColor yellowColor];
[self.view addSubview:myscroll];
[myscroll release];
myscroll.contentSize = CGSizeMake(3 * 375, 667);
myscroll.pagingEnabled = YES;
//第一个scrollView
self.myscroll1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
self.myscroll1.backgroundColor = [UIColor redColor];
[myscroll addSubview:self.myscroll1];
self.myscroll1.maximumZoomScale = 2.0;
self.myscroll1.minimumZoomScale = 0.5;
self.myscroll1.delegate = self;
[self.myscroll1 release];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
imageView1.image = [UIImage imageNamed:@"0.jpg"];
[self.myscroll1 addSubview:imageView1];
[imageView1 release];
//第二个scrollView
self.myscroll2 = [[UIScrollView alloc] initWithFrame:CGRectMake(375, 0, 375, 667)];
self.myscroll2.backgroundColor = [UIColor redColor];
[myscroll addSubview:self.myscroll2];
self.myscroll2.maximumZoomScale = 2.0;
self.myscroll2.minimumZoomScale = 0.5;
self.myscroll2.delegate = self;
[self.myscroll2 release];
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
imageView2.image = [UIImage imageNamed:@"1.jpg"];
[self.myscroll2 addSubview:imageView2];
[imageView2 release];
//第二个scrollView
self.myscroll3 = [[UIScrollView alloc] initWithFrame:CGRectMake(750, 0, 375, 667)];
self.myscroll3.backgroundColor = [UIColor redColor];
[myscroll addSubview:self.myscroll3];
self.myscroll3.maximumZoomScale = 2.0;
self.myscroll3.minimumZoomScale = 0.5;
self.myscroll3.delegate = self;
[self.myscroll3 release];
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
imageView3.image = [UIImage imageNamed:@"2.jpg"];
[self.myscroll3 addSubview:imageView3];
[imageView3 release];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
//缩放scrollView
//2.指定一个scrollView的子视图,跟着scrollView放大缩小
//有两点需要注意的
//1.scrollView放大缩小之后,contentSize会和子视图frame的size一样大
//2.scrollView的滚动条也是两个视图,都是UIImageView,会始终处在显示的最上面(也就是子视图数组的最后面 )
return [self.myscroll1.subviews firstObject];
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货