How to zoom into a selected area of image in iPhone?

情到浓时终转凉″ 提交于 2020-01-01 17:27:12

问题


I have an ImageView when clicked on that imageview, transparent circle should be created and again when double clicking on that circle, particular Image in that circle area should be zoomed.Any suggestion would be appreciated.


回答1:


I think this code will helpfull to you

- (id)initWithImage:(UIImage *)image {
    self = [super initWithImage:image];
    if (self) {
        [self setUserInteractionEnabled:YES];

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
        UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];

        [doubleTap setNumberOfTapsRequired:2];
        [twoFingerTap setNumberOfTouchesRequired:2];

        [self addGestureRecognizer:singleTap];
        [self addGestureRecognizer:doubleTap];
        [self addGestureRecognizer:twoFingerTap];

        [singleTap release];
        [doubleTap release];
        [twoFingerTap release];
    }
    return self;
}

#pragma mark Private

- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
    if ([delegate respondsToSelector:@selector(tapDetectingImageView:gotSingleTapAtPoint:)])
        [delegate tapDetectingImageView:self gotSingleTapAtPoint:[gestureRecognizer locationInView:self]];
}

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
    if ([delegate respondsToSelector:@selector(tapDetectingImageView:gotDoubleTapAtPoint:)])
        [delegate tapDetectingImageView:self gotDoubleTapAtPoint:[gestureRecognizer locationInView:self]];
}

- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer {
    if ([delegate respondsToSelector:@selector(tapDetectingImageView:gotTwoFingerTapAtPoint:)])
        [delegate tapDetectingImageView:self gotTwoFingerTapAtPoint:[gestureRecognizer locationInView:self]];
}


来源:https://stackoverflow.com/questions/18800754/how-to-zoom-into-a-selected-area-of-image-in-iphone

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