0

たとえば、iPad の画面全体を覆う 100 x 100 ピクセルの円をメイン ビューに描画する場合は、initWithFrame次の 2 つの手順を使用する代わりに、次のようにしますviewDidLoad

UINodeView *nodeView = [[UINodeView alloc] initWithFrame:
                               CGRectMake(x, y, NSNodeWidth, NSNodeHeight)];
nodeView.center = CGPointMake(x, y);

xとは、 の代わりに円を水平方向に中央揃えにするため、yより洗練されているためです。最初にフレームで、次に中心をリセットするのが良い方法ですか、それともより良い方法がありますか?self.view.bounds.size.width / 2self.view.bounds.size.width / 2 - NSNodeWidth / 2initinitWithCenterAndSize

4

2 に答える 2

1

私は通常これを行います:

UINodeView *nodeView = [[UINodeView alloc] initWithFrame:
                           CGRectMake(0, 0, NSNodeWidth, NSNodeHeight)];
nodeView.center = CGPointMake(x, y);

すっきりと綺麗に見えます。

于 2012-09-06T09:10:06.680 に答える