1

我已经尝试为此寻找答案,但我不知道要搜索什么,而且我束手无策。我有一个 UIScrollView,当缩放时,它会完全翻转,并且图像在完全消失之前到处出现故障。有时,它甚至会暂时搞砸其他组件,这些组件甚至不属于发生缩放的 UIScrollView 的一部分。我很抱歉我不能更技术。我什至不知道要看我的代码的哪一部分。

我制作了一个视频,因为我没有技术术语来描述这里发生的事情。任何帮助,将不胜感激。

https://www.youtube.com/watch?v=SvhqHI-3_g8

红色是我当前的 UIScrollView 背景。别介意。

视图控制器.h

@interface ViewController : UIViewController <UIActionSheetDelegate, UIImagePickerControllerDelegate, UIScrollViewDelegate>

@property (strong, nonatomic) UIImage *workingImage;
@property (weak, nonatomic) IBOutlet UIImageView *chosenImageView;
@property (weak, nonatomic) IBOutlet UIScrollView *imageScroller;

-(IBAction)cameraButtonPressed;

@end

视图控制器.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.imageScroller.minimumZoomScale = 1.00f;
    self.imageScroller.maximumZoomScale = 15.0f;
    self.imageScroller.contentSize = self.imageScroller.frame.size;
    self.imageScroller.scrollEnabled = YES;
}

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

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self.chosenImageView setImage:chosenImage];
    [self.imageScroller setContentSize:chosenImage.size];

    [self dismissViewControllerAnimated:YES completion:nil];
}
4

1 回答 1

1

看看这篇文章是否有帮助。似乎缺少的 ScrollViewDidZoom 方法可能是保持缩放视图到位的关键。http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content

于 2013-06-23T19:43:28.100 回答