LoginSignup
35
32

More than 5 years have passed since last update.

穴を空ける for チュートリアル

Last updated at Posted at 2014-04-29

チュートリアル用にこんな感じで、特定のスポットに穴を空けて表示したい。

Screenshot

利用する側

穴を空ける場所と、穴の大きさを指定して使うようにしたい。

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // 初回ヘルプ表示
    SpotHelpView *spotHelpView = [[SpotHelpView alloc] initWithFrame:self.view.window.bounds];
    [spotHelpView makeHoleAt:CGPointMake(290, 45) radius:30];
    [self.view.window addSubview:spotHelpView];
}

ビューの定義

@interface SpotHelpView : UIView

-(void) makeHoleAt:(CGPoint)point radius:(CGFloat)radius;

@end

ビューの実装

@implementation SpotHelpView

-(id) initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.5;
    }
    return self;
}

-(void) makeHoleAt:(CGPoint)point radius:(CGFloat)radius {
    CAShapeLayer *mask = [[CAShapeLayer alloc] init];
    mask.fillRule = kCAFillRuleEvenOdd;
    mask.fillColor = [UIColor blackColor].CGColor;

    // 画面全体
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:self.bounds];
    // 穴を空ける
    [maskPath moveToPoint:point];
    [maskPath addArcWithCenter:point radius:radius startAngle:0 endAngle:2 * M_PI clockwise:YES];

    mask.path = maskPath.CGPath;
    self.layer.mask = mask;
}

@end
35
32
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
35
32