タップジェスチャレコグナイザを使用したビューがあります。触ると背景色が変わるアニメーションが流れます。私の問題は、ビューをサブクラス化して drawRect メソッドをオーバーライドすると、アニメーションが再生されなくなることです...どうすればこれを修正できますか? 私の英語で申し訳ありませんが、事前に感謝します=)
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
NSLog(@"DrawRect test");
//H Black line
CGContextRef c = UIGraphicsGetCurrentContext();
CGFloat black[4] = {0.0f, 0.0f, 0.0f, 0.5f};
CGContextSetStrokeColor(c, black);
CGContextBeginPath(c);
CGContextMoveToPoint(c, 319.0f, 0.0f);
CGContextAddLineToPoint(c, 319.0f, 55.0f);
CGContextStrokePath(c);
//H White Line
c = UIGraphicsGetCurrentContext();
CGFloat white[4] = {1.0f, 1.0f, 1.0f, 0.1f};
CGContextSetStrokeColor(c, white);
CGContextBeginPath(c);
CGContextMoveToPoint(c, 0.0f, 1.0f);
CGContextAddLineToPoint(c, 320.0f, 1.0f);
CGContextStrokePath(c);
//V White Line
c = UIGraphicsGetCurrentContext();
CGContextSetStrokeColor(c, black);
CGContextBeginPath(c);
CGContextMoveToPoint(c, 0.0f, 54.0f);
CGContextAddLineToPoint(c, 320.0f, 54.0f);
CGContextStrokePath(c);
}
そして私のアニメーション:
//Debut
if (sender.state == UIGestureRecognizerStateBegan) {
[UIView animateWithDuration:0.7 animations:^{
[self.foreView setBackgroundColor:RGBA(RED_CELL, GREEN_CELL, BLUE_CELL, 0.6f)];
}];
}
//Fin
if (sender.state == UIGestureRecognizerStateEnded) {
[UIView animateWithDuration:0.4 animations:^{
[self.foreView setBackgroundColor:[UIColor clearColor]];
}];
}
サブビューの追加方法
//foreView
_foreView = [[ForeViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 55)];
[self.foreView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.foreView setBackgroundColor:[UIColor clearColor]];
[self.contentView addSubview:self.foreView];