2
UIImageViewのレイヤーにトランスフォームを適用する際に問題が発生しています。以下のコードを使用して、この針を回転しようとしていますが、重複したコピーが描画されています。私は、針の画像が追加された場所が他にないことを確認しており、addSubview
をコメントアウトするとどちらも表示されないので、間違いなく2度描いています。UIImageViewとCGAffinetransformで描画された重複レイヤー
左の針は、画像ビューが開始される位置、-20
にあります。右の針は回転し、needleValue
の正しい値を表示する態様で機能します。重複ドローを取得するために私は間違って何をしていますか?
- (UIImageView *)needle {
if (_needle == nil) {
UIImage *image = [UIImage imageNamed:@"needle.png"];
self.needle = [[[UIImageView alloc] initWithImage:image] autorelease];
[_needle sizeToFit];
[_needle setFrame:CGRectMake(floor((self.width - _needle.width)/2),
self.height - _needle.height + 68, // this - offset comes from the lowering of the numbers on the meter
_needle.width, _needle.height)];
_needle.contentMode = UIViewContentModeCenter;
_needle.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
_needle.autoresizesSubviews = YES;
// CALayer's transform property is a CATransform3D.
// rotate around a vector (x, y, z) = (0, 0, 1) where positive Z points
// out of the device's screen.
_needle.layer.anchorPoint = CGPointMake(0.05,1);
[self addSubview:_needle];
}
return _needle;
}
- (void)updateNeedle {
[UIView beginAnimations:nil context:NULL]; // arguments are optional
[UIView setAnimationDuration:VU_METER_FREQUENCY];
CGFloat radAngle = [self radianAngleForValue:needleValue];
self.needle.transform = CGAffineTransformMakeRotation(radAngle);
[UIView commitAnimations];
}
私は以前これを試していないのは馬鹿だと感じています...私はちょうどコード検査を使いました。 – coneybeare