macOS/iOS API解説

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

目次

NSIntersectionRect

二つの矩形が重なる部分の矩形を返します
NSRect  NSIntersectionRect ( 
         NSRect   aRect , 
         NSRect   bRect );

解説

二つの矩形が重なる部分の矩形を返します。

返り値

引数

( NSRect )aRect
( NSRect )bRect

クラス

NSIntersectionRect

Function

使用可能

10.0

参照

NSUnionRect

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSRect rect;
NSRect aFrame = NSMakeRect(0,0,100,100);
NSRect bFrame = NSMakeRect(50,50,100,100);

rect = NSIntersectionRect (aFrame,bFrame);


[image lockFocus];//imageにフォーカス

[[NSColor blueColor] set];//青色で塗る
NSRectFill(aFrame);
[[NSColor redColor] set];//赤色で塗る
NSRectFill(bFrame);
[[NSColor grayColor] set];//灰色で塗る
NSRectFill(rect);


[image unlockFocus];//フォーカス外す
}

@end