のサブレイヤーとして追加したレイヤーがありUIWebView
ます。レイヤーをタッチしてドラッグできるようにしたいと思います。を追加する前はUIWebView
、問題なくレイヤーをタッチしてドラッグできました。
ここでレイヤーを作成し、サブレイヤーとして追加します
- (void)viewDidLoad
{
[super viewDidLoad];
starLayer = [CALayer layer];
starLayer.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage
imageNamed:@"star"]].CGColor;
starLayer.shadowOffset = CGSizeMake(0, 3);
starLayer.shadowRadius = 5.0;
starLayer.shadowColor = [UIColor blackColor].CGColor;
starLayer.shadowOpacity = 0.8;
starLayer.frame = CGRectMake(235.0, 200.0, 35.0, 35.0);
[self.aboutWebView.layer addSublayer:starLayer];
[self moveStar];
}
これが私のmoveStar
方法です
- (void)moveStar
{
CAKeyframeAnimation *move = [CAKeyframeAnimation animationWithKeyPath:@"position"];
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCGPoint:CGPointMake(250.0, 50.0)]];
[values addObject:[NSValue valueWithCGPoint:CGPointMake(250.0, 250.0)]];
[move setValues:values];
[move setDuration:1.0];
[move setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
// Add the animation to the layer to be animated
[starLayer addAnimation:move forKey:@"moveAnimation"];
}
ここまでは順調ですね。星が画面に落ちて、真ん中の少し上に着地します。しかし、星に触れようとしても何も起こりません。touchesBegan
何らかの理由で呼び出されることはありません。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.aboutWebView];
[starLayer setPosition:point];
}
aboutWebView
タッチがレイヤーではなくビューに報告されるため、サブレイヤーのときにスターにタッチできないのはなぜですか?
星をタッチ可能なサブレイヤーとして作成する方法について何か提案はありますaboutWebView
か? 出来ますか?
ありがとうございました!