LoginSignup
0
0

More than 5 years have passed since last update.

スポットライト的なことをするビュー

Posted at

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];
}

centerOfHoleradiusOfHoleを変更することでライトの位置を動かす。
動かすのはNSTimerでやっている。

使い方としては、


SWHSpotlightView *spotlightView = [[SWHSpotlightView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
[spotlightView moveCenterTo:CGPointMake(160, 160) animated:YES];
[spotlightView changeRadiusTo:100 animated:YES];

のようなもの。他にdurationcompletionを指定できるメソッドもある。

また、

spotlightView.zoomInOutAnimation = YES;

とするとふわふわ微妙に拡大縮小を続ける。

何かの参考になれば。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0