UIView
インジケーターのスプライトを含むゲージ ダイヤルを表示するサブクラスを実装しています。針をさまざまな角度に向けるために変更できる角度プロパティがあります。それは機能しますが、針の位置の同じ値で、電話とシミュレーターの異なる場所に表示されます。iPhone 4 ですので、解像度が 2 倍になっていることが原因だと思いますが、どうすればよいかわかりません。を設定しようとしましたUIView's
layer's
contentScaleFactor
が、失敗します。UIView
無料で解像度のものを手に入れたと思いました。助言がありますか?
NSLog
ステートメント.frame.size.
は、シミュレーターとデバイスの両方で、両方の次元で150 を報告していることに注意してください。
ここに.mファイルがあります
更新: シミュレーターで、ハードウェアを iPhone 4 に設定する方法を見つけました。今のデバイスと同じように見えます。どちらもスプライトを半分のサイズでスケーリングおよび配置しています。
更新 2: 回避策を作成しました。.scale
スプライトの を に等しく設定しUIView's contentScaleFactor
、それを使用して、UIView
低解像度の画面の場合は半分に、高解像度の場合は全幅にダイビングします。ピクセルではなくポイントで作業する必要があるため、これが必要な理由はまだわかりません。Sprite
またはVectorSprite
クラスのカスタム描画コードと何らかの関係があるはずです。
誰かが何かを持っているなら、私はまだいくつかのフィードバックをいただければ幸いです...
#import "GaugeView.h"
@implementation GaugeView
@synthesize needle;
#define kVectorArtCount 4
static CGFloat kVectorArt[] = {
3,-4,
2,55,
-2,55,
-3,-4
};
- (id)initWithCoder:(NSCoder *)coder {
if (self = [super initWithCoder:coder]) {
needle = [VectorSprite withPoints:kVectorArt count:kVectorArtCount];
needle.scale = (float)self.contentScaleFactor; // returns 1 for lo-res, 2 for hi-res
NSLog(@" needle.scale = %1.1f", needle.scale);
needle.x = self.frame.size.width / ((float)(-self.contentScaleFactor) + 3.0); // divisor = 1 for hi-res, 2 for lo-res
NSLog(@" needle.x = %1.1f", needle.x);
needle.y = self.frame.size.height / ((float)(-self.contentScaleFactor) + 3.0);
NSLog(@" needle.y = %1.1f", needle.y);
needle.r = 0.0;
needle.g = 0.0;
needle.b = 0.0;
needle.alpha = 1.0; }
}
self.backgroundColor = [UIColor clearColor];
return self;
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGAffineTransform t0 = CGContextGetCTM(context);
t0 = CGAffineTransformInvert(t0);
CGContextConcatCTM(context, t0);
[needle updateBox];
[needle draw: context];
}
- (void)dealloc {
[needle release];
[super dealloc];
}
@end