UITapGestureRecognizer在缩放UIView后识别出来

时间:2012-04-10 05:07:03

标签: ios uigesturerecognizer

我有一个UIView,点击它后我会缩放到4倍。它工作正常。在下一次点按我想恢复到原始大小。问题是它只能在缩放前UIView中较小的矩形中识别出点击。我想在缩放UIView中的任何位置识别点击。我怎样才能实现它?

//Tapping code
titleCard = [[UIView alloc] initWithFrame: myrect];
[self addSubview:titleCard];
[titleCard release];

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeSize:)];
[tapRecognizer setNumberOfTouchesRequired:1];
[tapRecognizer setNumberOfTapsRequired:1];
[titleCard addGestureRecognizer:tapRecognizer];
[tapRecognizer release];

//Scaling code
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[scale setBeginTime:CACurrentMediaTime()+0.75];
[scale setDuration:0.5];
[scale setToValue: [NSNumber numberWithFloat:4.0f]];
[scale setRemovedOnCompletion:NO];
[scale setFillMode:kCAFillModeForwards];

感谢。

2 个答案:

答案 0 :(得分:1)

我不确定这里有什么不起作用,我替换了下面的代码。

//Scaling code 
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
[scale setBeginTime:CACurrentMediaTime()+0.75]; 
[scale setDuration:0.5]; 
[scale setToValue: [NSNumber numberWithFloat:4.0f]]; 
[scale setRemovedOnCompletion:NO]; 
[scale setFillMode:kCAFillModeForwards];
[titleCard.layer addAnimation:scale forKey:@"Scale"];

[UIView beginAnimations:@"Scale" context:nil];
[UIView setAnimationDelay:0.75];
[UIView setAnimationDuration:0.5];

[titleCard setTransform:CGAffineTransformMakeScale(4.0f, 4.0f);

[UIView commitAnimations];

现在,在UIView之前,点击次数被识别,而不是在缩放之前识别出较小的矩形。

答案 1 :(得分:-1)

它始终认为所有的水龙头都相似 在这里你可以把任何计数器值像

static NSInteger * counter = 0;

如果count等于0,则将其设为1,如果count等于1,则将其设为0

现在根据计数值你可以放大和缩小。