1

专家!!请帮助我!!!!在我的项目中,我以编程方式创建多个 UIImageview。我想在每个 ImageView.i 上添加捏手势我的代码在下面......

-(IBAction)addSymbols:(UIButton *)sender{
if (sender.tag ==1) {
CGRect frame =sender.frame;
[self.imgView setFrame:frame];
self.imgView.userInteractionEnabled = YES;
[imgView setImage:[sender imageForState:UIControlStateNormal]];
[self.view addSubview:imgView];
[self addGestureRecognizersToPiece:imgView];}

像这样,我添加了 5 个 imageViews。现在 [self addGestureRecognizersToPiece:imgView] 的代码

- (void)addGestureRecognizersToPiece:(UIView *)piece{
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)];
[piece  addGestureRecognizer:pinchGesture];

//In above add gesture on UIImageView directly its not working..
//if replace this line by [self.view addGestureRecognizer:pinchGesture]; it's working..
//but while pinch whole UIview scale

[pinchGesture setDelegate:self]; }

另一个错误是 UIPinchgesture 不能单独在多个 UIImageViews 上正确工作。所以请帮助我..尽快回复我..

- (void) scalePiece:(UIPinchGestureRecognizer*)paramSender{ 

if (paramSender.state == UIGestureRecognizerStateEnded) { 
self.currentScale = paramSender.scale;
} 
else if (paramSender.state == UIGestureRecognizerStateBegan && self.currentScale != 0.0f){ 

paramSender.scale = self.currentScale; }
 if (paramSender.scale != NAN && paramSender.scale != 0.0){ 
[paramSender view].transform= CGAffineTransformMakeScale(paramSender.scale, paramSender.scale); 
} 

正如你告诉我的,我为每个 UIImageView 添加了 userInteractionEnabled = YES。我也在我的代码中提到

4

2 回答 2

0

您应该userInteractionEnabled在 UIImageViews 上启用。默认情况下禁用此功能。

如果您需要更多帮助,请向我们展示您的scalePiece:代码。

于 2012-05-08T11:27:22.567 回答
0

将 imageViews 添加为 ScrollView 的子视图。

然后设置scrollView的scrollView zoomScale。还要实现 scrollView 的委托方法,尤其是下面的委托方法。

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

返回要缩放的 imageView 对象。

参考这些 UIScrollView

UIScrollViewDelegate

于 2012-05-08T11:50:11.357 回答