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. So your image_15
center should be set like
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
)
I can refine my answer if you provide me details about your view hierarchy incode.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.