简体   繁体   English

点按手势不起作用

[英]Tap gesture not working

I am developing an app in which user can add some icons like hat, hair on the captured picture.For this I have a image view on the screen to hold the captured image and below this I have a scrollview to display various icons that user can apply. 我正在开发一个应用程序,其中用户可以在捕获的图片上添加一些图标,例如帽子,头发。为此,我在屏幕上有一个图像视图来保存捕获的图像,在此之下我有一个滚动视图来显示用户可以使用的各种图标应用。 When I tap any icon placed inside the scroll view, I need to move this icon to the center captured picture, but when I tried it with code this sets the image to the center of the scroll view not the entire view. 当我点击放置在滚动视图内的任何图标时,我需要将该图标移动到捕获的图片的中心,但是当我尝试使用代码将其设置为滚动视图的中心而不是整个视图的中心时。 But when I remove the scroll view and put the image outside the image view this works. 但是,当我删除滚动视图并将图像放在图像视图之外时,此方法有效。 Please suggest. 请提出建议。

//In view Did Load //鉴于加载了

//*************************************adding gusture******************************
    //SINGLETAP
    UITapGestureRecognizer *singleTapGestureRecognizer_For_image15 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapAction_For_Image_15:)];
    singleTapGestureRecognizer_For_image15.numberOfTapsRequired = 1;
    [self.image_15 addGestureRecognizer:singleTapGestureRecognizer_For_image15];
    //DOUBLE TAP
    UITapGestureRecognizer *doubleTapGestureRecognizer_For_image15 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapAction_For_Image_15:)];
    doubleTapGestureRecognizer_For_image15.numberOfTapsRequired = 2;
    [self.image_15 addGestureRecognizer:doubleTapGestureRecognizer_For_image15];
    //End Image 15








//***********************************Handling Tap
//SIngle TAP

-(void)handleSingleTapAction_For_Image_15:(UITapGestureRecognizer *)handleSingleTapAction_For_Image_15{
    CGSize newSize = CGSizeMake(250.0, 250.0);
    CGPoint currentCenter = self.view.center;
    self.image_15.frame = CGRectMake(self.image_15.frame.origin.x, self.image_15.frame.origin.y, newSize.width, newSize.height);
    self.image_15.center = currentCenter;
}

//Double Tap
-(void)handleDoubleTapAction_For_Image_15:(UITapGestureRecognizer *)doubleTapGestureRecognizer_For_image15
{
    CGSize newSize = CGSizeMake(40.0, 40.0);
    CGPoint currentCenter = self.view.center;
    self.image_15.frame = CGRectMake(self.image_15.frame.origin.x, self.image_15.frame.origin.y, newSize.width, newSize.height);
    self.image_15.center = currentCenter;
}

You are setting the center of the image from the self.view's center but I think you also have to take care of the scrollview frame offset from origin. 您是从self.view的中心设置图像的中心,但我认为您还必须注意scrollview框架与原点的偏移量。 So your image_15 center should be set like 因此,您的image_15中心应设置为

self.image_15.center = CGPointMake(currentCenter.x-yourScrollView.frame.origin.x, currentCenter.y-yourScrollView.frame.origin.y);
(provided scrollview is also a direct subview of self.view ) (提供滚动视图也是一个直接子视图self.view

I can refine my answer if you provide me details about your view hierarchy incode. 如果您向我提供有关视图层次结构incode的详细信息,我可以完善我的答案。

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

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