0

私は iOS アプリを開発していますが、画面上にいくつかの描画があり、その方法を学んでいます。

ビューで UIBezierPath を表示するからコードをコピーしました。これはすべて、FirstViewController クラスの viewDidLoad 関数に入れられます。

UIBezierPath *circle = [UIBezierPath
                    bezierPathWithOvalInRect:CGRectMake(75, 100, 200, 200)];  

//you have to account for the x and y values of your UIBezierPath rect 
//add the x to the width (75 + 200)
//add the y to the height (100 + 200)
UIGraphicsBeginImageContext(CGSizeMake(275, 300));

//this gets the graphic context
CGContextRef context = UIGraphicsGetCurrentContext();

//you can stroke and/or fill
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor lightGrayColor].CGColor);
[circle fill];
[circle stroke];

//now get the image from the context
UIImage *bezierImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageView *bezierImageView = [[UIImageView alloc]initWithImage:bezierImage];
[self.view addSubview:circle];

これでうまくいき、円が完全に私の視界に描かれました。私が抱えている問題は、宣言する代わりに

UIBezierPath *circle = [UIBezierPath
                bezierPathWithOvalInRect:CGRectMake(75, 100, 200, 200)];  

別のクラスには、UIBezierPath 型の変数があります。そのクラスのインスタンス変数を次のように FirstViewController.h に含めました。

@property MyClass myClass;

そのクラスでは:

@interface MyClass: UIView
@property UIBezierPath *shapeToBeDrawn;

したがって、viewDidLoad で UIBezierPath を宣言する代わりに、これはクラスの単なるインスタンス変数です。しかし、私がこれを行うとき:

self.myClass.shapeToBeDrawn = [UIBezierPath
                    bezierPathWithOvalInRect:CGRectMake(75, 100, 200, 200)]; 

画面には描画されません。

viewDidLoad で正しく宣言することと、UIBezier 変数を別のクラスの一部にすることの違いは何ですか?

4

0 に答える 0