专家!!请帮助我!!!!在我的项目中,我以编程方式创建多个 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。我也在我的代码中提到