pinch to zoom using uiscrollview

江枫思渺然 提交于 2019-12-23 02:18:31

问题


I am trying to do a pinch to zoom with a uiscrollview that only has a backgroudnd image. First of all is this possible? Secondly can I do this with interface builder?

Basicly all I have atm is this

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

    scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    scrollView.backgroundColor = [UIColor blackColor];
    scrollView.delegate = self;
    scrollView.bounces = NO;
    scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"auckland-300.jpg"]];
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
    scrollView.contentSize = image.frame.size;
    [scrollView addSubview:image];
    scrollView.minimumZoomScale = scrollView.frame.size.width / image.frame.size.width;
    scrollView.maximumZoomScale = 2.0;
    [scrollView setZoomScale:scrollView.minimumZoomScale];
    self.view = scrollView;

}

Any help would be appreciated


回答1:


You need to implement the UIScrollViewDelegate method.

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

and have it return a reference to your image view. This means you might want to manage a reference to the UIImageView stored within the scroll view.

Oh, and yes, it is doable in Interface Builder.




回答2:


Check out my demo application here:http://rexstjohn.com/facebook-like-ios-photo-modal-gallery-swipe-gestures/.

It demonstrates pinch to zoom of photos in a scrollview as well as a few other common functions you might want. Enjoy.



来源:https://stackoverflow.com/questions/8440586/pinch-to-zoom-using-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!