0

に追加されたビュー レイヤーのタッチ イベントを有効にする方法はありCAReplicatorLayerますか?

に を追加しUIButtonCAReplicatorLayerいます。ボタンの元のインスタンスと複製されたインスタンスの両方をタップ可能にしたいと考えています。

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");
}
4

1 に答える 1

0

レイヤーはタッチイベントを受信しないため、ボタン自体をコピーする必要があります。また、レイヤーだけでなく、ビュー階層にもボタンを追加する必要があります。

于 2015-08-28T08:26:55.797 に答える