2
UIImageView의 레이어에 변형을 적용하는 데 문제가 있습니다. 아래 코드를 사용하여이 바늘을 회전 시키려고 시도하지만 중복 사본이 그려집니다. 나는 바늘 이미지가 추가 된 다른 곳이 없다는 것을 확인했으며, addSubview
을 주석 처리하면 아무도 나타나지 않으므로 확실히 두 번 그립니다.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