我正在开发一个应用程序,用户可以在捕获的图片上添加帽子,头发等图标。为此我在屏幕上有一个图像视图来保存捕获的图像,在这下面我有一个滚动视图来显示各种图标该用户可以申请。 当我点击滚动视图内的任何图标时,我需要将此图标移动到中心捕获的图片,但是当我尝试使用代码时,这会将图像设置为滚动视图的中心而不是整个视图。 但是,当我删除滚动视图并将图像放在图像视图外时,这是有效的。请建议。
//在视图中加载
//*************************************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;
}
答案 0 :(得分:0)
您正在设置self.view中心的图像中心,但我认为您还必须处理从原点偏移的scrollview框架。因此,您的image_15
中心应设置为
self.image_15.center = CGPointMake(currentCenter.x-yourScrollView.frame.origin.x, currentCenter.y-yourScrollView.frame.origin.y);
(提供的scrollview也是self.view
)
如果您向我提供有关您的视图层次结构的详细信息,我可以优化我的答案。