未调用UIScrollView视图以进行缩放

时间:2012-02-07 13:50:21

标签: ios uiscrollview

我用页面制作了一个UIScrollView。在每个页面上,我将有一个带UIImageView的UIScrollView。我想以这种方式处理每页上的图像缩放。但是没有调用缩放委托方法。 这是我的代码:

verticalScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
            horizontalScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];



            verticalScroll.backgroundColor=[UIColor purpleColor];
            verticalScroll.pagingEnabled=YES;
            verticalScroll.contentSize=CGSizeMake(768*[largeImagesFromGallery count], 1024);


            horizontalScroll.backgroundColor=[UIColor blackColor];
           horizontalScroll.pagingEnabled=YES;
           horizontalScroll.contentSize=CGSizeMake(1024*[largeImagesFromGallery count], 768);

            float cofVert=1.34f;
            for(int i=0; i<[largeImagesFromGallery count]; i++)
            {
                UIImage *temp=[largeImagesFromGallery objectAtIndex:i];

                UIScrollView *svVert=[[UIScrollView alloc] initWithFrame:CGRectMake(i*768, 0, temp.size.width/cofVert, temp.size.height/cofVert)];

                svVert.contentSize=CGSizeMake(temp.size.width/cofVert, temp.size.height/cofVert);
                svVert.zoomScale=3.0f;
                svVert.delegate=self;


                UIImageView *imageVert=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, temp.size.width/cofVert, temp.size.height/cofVert)];
                imageVert.image=temp;

                imageVert.tag=2000;


                 UIScrollView *svHor=[[UIScrollView alloc] initWithFrame:CGRectMake(i*1024, 0, temp.size.width, temp.size.height)];
                svHor.delegate=self;
                svHor.contentSize=CGSizeMake(temp.size.width, temp.size.height);

                UIImageView *imageHor=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, temp.size.width, temp.size.height)];
                imageHor.image=temp;
                imageHor.tag=2000;

                [svVert addSubview:imageVert];
                [svHor addSubview:imageHor];
                [verticalScroll addSubview:svVert];
                [horizontalScroll addSubview:svHor];


                    //fr=CGRectMake(0, 0, 768, 1024);
                    //[verticalScroll addSubview:imageVert];
                  //  [horizontalScroll addSubview:imageHor];


            }
            //verticalScroll.delegate=self;
           // horizontalScroll.delegate=self;
            ambiancesON=YES;
            if(self.interfaceOrientation==UIInterfaceOrientationPortrait || self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
            {
                [self.view addSubview:verticalScroll];
            }
            else if(self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation==UIInterfaceOrientationLandscapeRight)
            {
                [self.view addSubview:horizontalScroll];

            }

所以现在我有缩放方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

    NSLog(@"Log log log");
    NSLog(@"VIew? %@", [[scrollView subviews]objectAtIndex:0]);

    return [[scrollView subviews]objectAtIndex:0];
}

没有调用缩放((

1 个答案:

答案 0 :(得分:1)

我认为你的设计存在缺陷。我建议为每个内部滚动视图(要响应缩放的那些)创建一个视图控制器类。这样,如果所有内容都正确连接(UIScrollView委托分配给内部视图控制器),它应该按预期工作。