有没有办法为添加到CAReplicatorLayer
的视图图层启用触摸事件?
我正在向UIButton
添加CAReplicatorLayer
,我希望能够同时按下该按钮的原始实例和重复实例。
到目前为止,我已尝试将UIView
-hitTest:withEvent:
和-touchesXXX:withEvent:
方法转发给该按钮,但对我来说还没有任何效果(如果可能的话)。
来自UIViewController
:
- (void)viewDidLoad
{
[super viewDidLoad];
static UIButton *button; // Temp hack to keep a ref to the button
button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(30, 100, 60, 44);
[button setTitle:@"Button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
CAReplicatorLayer *layer = [CAReplicatorLayer layer];
layer.frame = self.view.bounds;
layer.instanceCount = 2;
layer.instanceTransform = CATransform3DMakeTranslation(70, 0, 0);
[layer addSublayer:button.layer];
[self.view.layer addSublayer:layer];
}
- (void)buttonTapped:(id)sender
{
NSLog(@"Tapped");
}
答案 0 :(得分:0)
您需要复制按钮本身,因为图层未接收触摸事件。您还需要向视图层次结构添加按钮,而不仅仅是图层。