2017-06-09 5 views
0

私はXamarinにUIView子孫を書き、Drawメソッドをオーバーライドしました。 他のスタッフの中では、テキストを描画します。どの画面の向きにも見えますが、デバイスを他の向きに回転させると、テキストが伸び縮みします。 originalrotated screen 描画コードは次のとおりです。iPhoneを横向きに回転させるとテキストが伸びるのはなぜですか?

public override void Draw(CGRect rect) 
{ 
    base.Draw(rect); 
    var ss = new UIStringAttributes(); 
    ss.ForegroundColor = mTextColor; 
    ss.Font = mTextFont; 
    ss.ParagraphStyle = new NSMutableParagraphStyle() { Alignment = UITextAlignment.Center }; 
    using (var g = UIGraphics.GetCurrentContext()) 
    { 
     for (nint i = 0; i < mBars.Length; ++i) 
     { 
      var r = mBars[i]; 
      g.SetFillColor(i + 1 == mBars.Length ? mLastBarColor : mBarColor); 
      g.FillRect(r); 

      var ns = new NSAttributedString(mDataSource[i].Item2, ss); 
      var textRect = new CGRect(r.Left, r.Bottom, r.Width, mTextRectHeight); 
      ns.DrawString(textRect); 
     } 
    } 
} 
+0

あなたは向きを変えてもイメージを再描画しないので、既存のイメージが引き伸ばされ/圧縮されます。あなたはオリエンテーションの変更に再描画を強制する必要があります – Russell

+0

@Russel、はい、あなたは正しいです! –

答えて

0

ラッセルは正しいです。私はUIView contentModeについて知らなかった。 これは '再描画'に設定する必要があります

関連する問題