変数bounds、widthおよびheightは現在のローカル変数です。私は他のクラスからアクセスできず、別の方法でアクセスすることもできません。変数を他のクラスにアクセスさせるにはどうすればよいですか?
これらの変数をインスタンス全体で使用できるようにするにはどうすればよいですか?私はそれらを.hファイルの中に置き、CGFloatsに改名して無駄にしようとしました。
#import "TicTacToeBoard.h"
@implementation TicTacToeBoard
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGRect bounds = [self bounds];
float width = bounds.size.width;
float height = bounds.size.height;
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx, 0.3, 0.3, 0.3, 1);
CGContextSetLineWidth(ctx, 5);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextMoveToPoint(ctx, width/3, height * 0.95);
CGContextAddLineToPoint(ctx, width/3, height * 0.05);
CGContextStrokePath(ctx);
}
@end
は知らん笑。これを他の方法に再入力すると、変数をよりアクセスしやすくするよりも練習が悪くないでしょうか?私は、インスタンスの属性を記述するときにそれらをローカル変数として保持する理由は見当たりません。 – Deco