1

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
4

1 に答える 1

1

答えは、iOSがdrawRectメソッドで自動的に解像度のスケーリングを処理するということだと思いますが、カスタムの描画コードでは、自分で行う必要があります。

私の例では、を使用しUIView's contentsScaleFactorてスプライトをスケーリングしました。将来的には、カスタムdrawメソッド(図には示されていません)で[UIScreen mainScreen] scale、それに応じてクエリとスケーリングを行います。

于 2010-09-08T13:57:09.090 に答える