私は実行しようとしているこの非常に簡単なテストを今すぐ中止します。私は何もしませんが、iPhoneの画面の1つのコーナーからもう一方に線を描画し、touchesMoved()を使用して最後の点から現在の点までの線を描くことになっているサブビューを追加します。 問題: 1.すでに初期行は表示されていません。 2. Interface Builderを使用すると、初期行が表示されますが、SetNeedsDisplay()を呼び出してもdrawRect()は呼び出されません。MonoTouchの非常に簡単なテストビューでは、Core Graphicsを使用して線を描画しますが、表示内容は表示されません。
これは難しいことではありません。誰かが以下のコードを修正して動作させることはできますか? FinishedLaunchingでmain.csで
():
oView = new TestView();
oView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
oView.Frame = new System.Drawing.RectangleF(0, 0, 320, 480);
window.AddSubview(oView);
window.MakeKeyAndVisible();
TestView.cs:
using System;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.Foundation;
namespace Test
{
public class TestView : UIView
{
public TestView() : base()
{
}
public override void DrawRect (RectangleF area, UIViewPrintFormatter formatter)
{
CGContext oContext = UIGraphics.GetCurrentContext();
oContext.SetStrokeColor(UIColor.Red.CGColor.Components);
oContext.SetLineWidth(3.0f);
this.oLastPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oLastPoint.Y;
this.oCurrentPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oCurrentPoint.Y;
oContext.StrokeLineSegments(new PointF[] {this.oLastPoint, this.oCurrentPoint });
oContext.Flush();
oContext.RestoreState();
Console.Out.WriteLine("Current X: {0}, Y: {1}", oCurrentPoint.X.ToString(), oCurrentPoint.Y.ToString());
Console.Out.WriteLine("Last X: {0}, Y: {1}", oLastPoint.X.ToString(), oLastPoint.Y.ToString());
}
private PointF oCurrentPoint = new PointF(0, 0);
private PointF oLastPoint = new PointF(320, 480);
public override void TouchesMoved (MonoTouch.Foundation.NSSet touches, UIEvent evt)
{
base.TouchesMoved (touches, evt);
UITouch oTouch = (UITouch)touches.AnyObject;
this.oCurrentPoint = oTouch.LocationInView(this);
this.oLastPoint = oTouch.PreviousLocationInView(this);
this.SetNeedsDisplay();
}
}
}
があるのみ(RectangleF)とのdrawRect(RectangleF、UIViewPrintFormatter)を描くので、私はあなたが ")(描画" を参照してくださいと仮定上書きしたいです。そしてそれは動作します!昨日私はあまりにも疲れていたようですね。ありがとう。 – Krumelur
もう1つ:LocationInView()の結果をMonotouchのGL座標に変換する必要はありませんか?私はObjCでそれをやっていましたが、どちらの場合も(0,0)のように思えます。 – Krumelur
あなたはかなり正しいです、私はそれに応じて私の答えを更新しました。ありがとう! LocationInViewについては、別個のobjcサンプルを投稿できますか?それと同等のことを教えてください。 –