我有一个3x3的UIViews网格,其中添加了UIGestureRecognizers,排列如下:
它的工作方式是点击正方形使用CGAffineTransformScale将其放大2倍,并覆盖其他正方形。问题是由于某种原因,触摸区域与1.0比例保持相同的大小。
我使用
添加方块CGRect squareFrame = CGRectMake(1 + squareSpacing + ((squareDimension + squareSpacing) * i), topMargin, squareDimension, squareDimension);
SquareView *square = [[SquareView alloc] initWithFrame:squareFrame];
[square setPosition:i];
square.layer.zPosition = 0;
[self.view addSubview:square];
[squaresArray addObject:square];
Squares在其init中添加了手势识别器:
fingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self addGestureRecognizer:fingerTap];
点击功能执行以下操作:
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:10.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGAffineTransform transform = self.transform;
self.transform = CGAffineTransformScale(transform, 2.0, 2.0);
}
completion:nil];
我用红色勾勒出触摸区域。我尝试过使用zPosition,但我不知道该怎么做才能使它工作,我被卡住了。我希望能够点击放大的任何地方来关闭它,但我只限于红色区域。
提前致谢。
编辑:抱歉图片太大了。代码已添加。
答案 0 :(得分:1)
您可能会尝试将展开的UIView置于父视图的前面,以便任何重叠视图都不会捕获您的点击事件:
[parentView bringSubviewToFront:tappedView];