Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // GestaltSmile
- //
- // Created by MizushimaYusuke on 7/27/16.
- // Copyright © 2016 MizushimaYusuke. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @property (nonatomic, weak) UIView *smilePullTab;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor colorWithHue:0.7 saturation:0.9 brightness:0.3 alpha:1];
- [self randomDotAndLine];
- [self createSmilePullTab];
- }
- - (void)randomDotAndLine {
- UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:20 startAngle:0 endAngle:M_PI * 0.4 clockwise:YES];
- for (int i=0; i<30; i++) {
- float x = arc4random() % 300 + 10;
- float y = arc4random() % 500 + 100;
- CAShapeLayer *mouth = [CAShapeLayer layer];
- mouth.path = path.CGPath;
- mouth.fillColor = [UIColor clearColor].CGColor;
- mouth.strokeColor = [UIColor whiteColor].CGColor;
- mouth.position = CGPointMake(x, y);
- [self.view.layer addSublayer:mouth];
- }
- for (int i=0; i<60; i++) {
- float x = arc4random() % 300 + 10;
- float y = arc4random() % 500 + 100;
- CALayer *dot = [CALayer layer];
- dot.frame = CGRectMake(x, y, 10, 10);
- dot.cornerRadius = 5;
- dot.backgroundColor = [UIColor whiteColor].CGColor;
- [self.view.layer addSublayer:dot];
- }
- }
- - (void)createSmilePullTab {
- UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:30 startAngle:0 endAngle:2.0 * M_PI clockwise:YES];
- UIView *tab = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.view.bounds) - 10, CGRectGetMidY(self.view.bounds) + 100, 100, 60)];
- tab.backgroundColor = [UIColor colorWithHue:0.2 saturation:0.8 brightness:0.5 alpha:1];
- [self.view addSubview:tab];
- CAShapeLayer *circle = [CAShapeLayer layer];
- circle.path = path.CGPath;
- circle.fillColor = tab.backgroundColor.CGColor;
- circle.position = CGPointMake(0, 30);
- [tab.layer addSublayer:circle];
- UIBezierPath *sPath = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:20 startAngle:M_PI * 0.3 endAngle:M_PI * 0.7 clockwise:YES];
- CAShapeLayer *mouth = [CAShapeLayer layer];
- mouth.position = CGPointMake(50, 30);
- mouth.path = sPath.CGPath;
- mouth.fillColor = [UIColor clearColor].CGColor;
- mouth.strokeColor = [UIColor whiteColor].CGColor;
- [tab.layer addSublayer:mouth];
- UIBezierPath *ePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(-20, -10) radius:5 startAngle:0 endAngle:2.0 * M_PI clockwise:NO];
- [ePath appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(20, -10) radius:5 startAngle:0 endAngle:2.0 * M_PI clockwise:NO]];
- CAShapeLayer *eyes = [CAShapeLayer layer];
- eyes.path = ePath.CGPath;
- eyes.fillColor = [UIColor whiteColor].CGColor;
- eyes.position = mouth.position;
- [tab.layer addSublayer:eyes];
- self.smilePullTab = tab;
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [UIView animateWithDuration:0.5 animations:^{
- self.smilePullTab.transform = CGAffineTransformMakeTranslation(-80, 0);
- }];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement