0

我有一个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];

谢谢。

4

2 回答 2

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,而不仅仅是在缩放发生之前的较小的矩形。

于 2012-04-16T04:53:59.350 回答
-1

它总是将所有水龙头识别为相似的,您可以输入任何计数器值,例如

静态 NSInteger *counter=0;

现在如果 count 等于 0 则设为 1,如果 count 等于 1 则设为 0

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

于 2012-04-10T07:16:08.930 回答