我可以滚动图像视图,但是缩放以放大/缩小不起作用。出了什么问题?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
UIImageView *imageView = [[UIImageView alloc] init];
[self.scrollView addSubview:imageView];
imageView.frame = CGRectMake(0, 0, chosenImage.size.width, chosenImage.size.height);
imageView.image = chosenImage;
self.scrollView.maximumZoomScale = 4;
self.scrollView.minimumZoomScale = 0.1;
self.scrollView.showsVerticalScrollIndicator=YES;
self.scrollView.delegate = self;
self.scrollView.scrollEnabled=YES;
self.scrollView.userInteractionEnabled=YES;
self.scrollView.contentSize = CGSizeMake(chosenImage.size.width, chosenImage.size.height);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:2)
首先要确保您的视图已实现正确的委托。例如,在.m文件中
@interface myViewController () <UIGestureRecognizerDelegate, UIScrollViewDelegate>
UIScrollView类可以有一个必须采用UIScrollViewDelegate协议的委托。要使缩放和平移工作,委托必须实现viewForZoomingInScrollView:和scrollViewDidEndZooming:withView:atScale:;此外,最大(maximumZoomScale)和最小(minimumZoomScale)缩放比例必须不同。
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.fullScreenView;
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}