滚动视图以放大分页滚动视图不缩放

时间:2020-01-14 21:04:10

标签: objective-c uiscrollview uiimageview

这是外部滚动视图中我的滚动视图的代码。此内部滚动视图包含应该可缩放的UIImageView,但它不起作用。此外,图像没有完全居中,我也不知道为什么。您能告诉我变焦缺少什么吗? (内部称为FMImageZoomController)

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //CGRect frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
    CGRect frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
    self.zoomScroller = [[UIScrollView alloc] initWithFrame:frame];

    self.zoomScroller.userInteractionEnabled = YES;
    self.zoomScroller.delegate = self;
    //self.zoomScroller.clipsToBounds = YES;

    self.imageView = [[UIImageView alloc] initWithFrame:frame];
    self.imageView.userInteractionEnabled = YES;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.zoomScroller addSubview:self.imageView];
    self.view = self.zoomScroller;

    float minimumScale = self.imageView.frame.size.width /self.zoomScroller.frame.size.width;
    self.zoomScroller.maximumZoomScale = 5.0f;  //Change as per you need
    self.zoomScroller.minimumZoomScale = minimumScale;  //Change as you need
    self.zoomScroller.zoomScale = minimumScale;
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}

编辑:我发现了一个错误,但无法解决。可缩放滚动视图调用分页滚动视图(外部滚动视图)的委托。但这没有任何意义,我从未将内部scrollview的委托设置为外部视图控制器。我只在内部设置它吗?我如何实现它只调用内部滚动视图?

这是我的外部代码,其中准备了所有分页的滚动视图:

-(void)prepareScrollView
{
    for(int i =0;i<[self.layoverPhotoAssets count];i++){
        PHAsset *asset = self.layoverPhotoAssets[i];

        FMImageZoomViewController *zoomController = [[FMImageZoomViewController alloc] init];
//        UIImageView *imageView = [[UIImageView alloc] init];
        int x = self.scrollView.frame.size.width * i;
        zoomController.view.frame = CGRectMake(x, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
        //zoomController.view.frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
        [self.scrollView addSubview:zoomController.view];
        zoomController.zoomScroller.delegate = zoomController;

        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
        options.resizeMode = PHImageRequestOptionsResizeModeFast;
        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; //I only want the highest possible quality
        options.synchronous = NO;
        options.networkAccessAllowed = YES;
        [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:self.scrollView.frame.size contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if(result){
                zoomController.imageView.image = result;
            }
        });
        }];

        //self.scrollView.contentSize= ;
    }
    [self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width * [self.layoverPhotoAssets count], 0)];
    [self scrollToAsset:self.selectedAsset];
}

0 个答案:

没有答案