Bir UIImageView katmanına dönüştürmeyi uygulayarak bir sorun yaşıyorum. Aşağıdaki kodu kullanarak, bu iğneyi döndürmeye çalışıyorum, ancak yinelenen kopyaları çiziyorum. İğne görüntünün eklendiği başka bir yer olmadığını kontrol ettim ve addSubview
yorumunu yapmak bir tane göstermiyor, bu yüzden kesinlikle iki kez çiziyor.Bir UIImageView ve CGAffinetransform ile çizilen yinelenen katmanlar
Soldaki iğne, görüntü görünümünün -20
adresinde başlatılması gereken konumdadır. Sağdaki iğne, döndürdüğü yönde çalışır ve needleValue
için doğru değeri görüntüler. Yinelenen çekiliş yapmak için ne yapıyorum?
- (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];
}
Bunu daha önce denemediğim için aptal gibi hissediyorum… Sadece kod incelemesi kullandım. – coneybeare