简体   繁体   English

UIImageView缩放,点击,手势不起作用

[英]UIImageView zoom, tap, gestures don't work

I am using Apple code for just zoom the UIImageView on taps and gestures. 我使用Apple代码只是将UIImageView缩放到水龙头和手势上。 But its not work ? 但是它行不通吗?

Please see this Apple's link apple code for image zooming by taps and gestures 请查看此Apple的链接Apple代码以通过点击和手势缩放图像

-(void)veiwDidLoad
{
    [super viewDidLoad];// Edited my self 

    imageView.userInteractionEnabled = YES; // Edited my self

    //All code below same.... like Apple's code

    // set the tag for the image view
    [imageView setTag:ZOOM_VIEW_TAG];

    // add gesture recognizers to the image view
    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];

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

    [singleTap release];
    [doubleTap release];
    [twoFingerTap release];

    // calculate minimum scale to perfectly fit image width, and begin at that scale
    float minimumScale = [imageScrollView frame].size.width  / [imageView frame].size.width;
    [imageScrollView setMinimumZoomScale:minimumScale];
    [imageScrollView setZoomScale:minimumScale];
}

Make sure that you set your imageView to be userInteractionEnabled = YES; 确保将userInteractionEnabled = YES;设置为userInteractionEnabled = YES; .. its assign to NO by default. ..默认情况下分配为NO

change the function name from 从更改功能名称

-(void) veiwDidLoad 

to

-(void) viewDidLoad

I has a problem like that as well, does that fix it? 我也有类似的问题,这可以解决吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM