macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

convertPoint:fromView:

別のビューの座標をレシーバの座標へ変換してNSPointを返します
-(NSPoint)convertPoint:(NSPoint)aPoint:
          fromView:(NSView *)aView:

解説

別のビュー(aView)の座標をレシーバの座標へ変換してNSPointを返します。
別のビュー(aView)がnilなら、ウインドウの座標になります。
別のビュー(aView)とレシーバーは、同じNSWindowにないといけません。

返り値

( NSPoint )

aViewのレシーバでの座標

引数

( NSPoint )aPoint

変換前の座標

( NSView * )aView

変換元のビュー

フレームワーク

ApplicationKit

クラス

NSView

Instance Methods

使用可能

10.0

参照

- convertRect:fromView:
- convertSize:fromView:
- ancestorSharedWithView:
- contentView (NSWindow)

例文

#import "MyScrollView.h"

@implementation MyScrollView
//ダブルクリックしたPointのXの値をtextFieldに入れる

//このスクロールビューのmouseDownをオーバーライド
- (void)mouseDown:(NSEvent *)theEvent {
    //ダブルクリックだったら
    if ([theEvent clickCount] > 1) {
    //ポイントを取得
        NSPoint curPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
        NSLog([NSString stringWithFormat:@"%.1f,%.1f",curPoint.x,curPoint.y]);
    }

    }
@end