githubのレポジトリ
基本的にはDrawRectでパスを描く。
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
[self.fillColor setFill];
CGRect holeRect = CGRectMake(self.centerOfHole.x - self.radiusOfHole , self.centerOfHole.y - self.radiusOfHole , self.radiusOfHole * 2, self.radiusOfHole * 2);
UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:holeRect];
[circlePath appendPath:[UIBezierPath bezierPathWithRect:rect]];
circlePath.usesEvenOddFillRule = YES;
[circlePath fill];
}
centerOfHole
やradiusOfHole
を変更することでライトの位置を動かす。
動かすのはNSTimer
でやっている。
使い方としては、
SWHSpotlightView *spotlightView = [[SWHSpotlightView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
[spotlightView moveCenterTo:CGPointMake(160, 160) animated:YES];
[spotlightView changeRadiusTo:100 animated:YES];
のようなもの。他にduration
とcompletion
を指定できるメソッドもある。
また、
spotlightView.zoomInOutAnimation = YES;
とするとふわふわ微妙に拡大縮小を続ける。
何かの参考になれば。