UIView
これを行うには、オーバーフロー領域で半透明、「クロップ」領域で透明なのサブクラスを作成し、それを自分の上に配置しUIScrollView
て、オーバーフローを覆うように拡張します。
実装する必要がある主なメソッドは次のinitWithFrame
とおりです。
#define kIDZAlphaOverlayDefaultAlpha 0.75
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
mAlpha = kIDZAlphaOverlayDefaultAlpha;
self.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:mAlpha];
self.userInteractionEnabled = NO;
}
return self;
}
そうしuserInteractionEnabled = NO
ないと、スクロール ビューにイベントが表示されません。
とdrawRect
- (void)drawRect:(CGRect)rect
{
CGRect apertureRect = /* your crop rect */;
CGContextRef context = UIGraphicsGetCurrentContext();
/* draw the transparent rect */
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextFillRect(context, apertureRect);
/* draw a white border */
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextStrokeRect(context, apertureRect);
}
ここで重要な点はkCGBlendModeCopy
、半透明の背景に透明な四角形を描画 (またはカット) できることです。
透明な四角形を角丸四角形にしたい場合は、トリミングされた画像のプレビューを含めると、次の画面のようになります。

申し訳ありませんが、スクリーン ショットのすべてのコードを共有することはできません。クライアントプロジェクトからのものです:-(