Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // GestaltSmile
  4. //
  5. // Created by MizushimaYusuke on 7/27/16.
  6. // Copyright © 2016 MizushimaYusuke. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12. @property (nonatomic, weak) UIView *smilePullTab;
  13. @end
  14.  
  15. @implementation ViewController
  16.  
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.view.backgroundColor = [UIColor colorWithHue:0.7 saturation:0.9 brightness:0.3 alpha:1];
  20. [self randomDotAndLine];
  21. [self createSmilePullTab];
  22. }
  23.  
  24. - (void)randomDotAndLine {
  25.  
  26. UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:20 startAngle:0 endAngle:M_PI * 0.4 clockwise:YES];
  27.  
  28. for (int i=0; i<30; i++) {
  29.  
  30. float x = arc4random() % 300 + 10;
  31. float y = arc4random() % 500 + 100;
  32.  
  33. CAShapeLayer *mouth = [CAShapeLayer layer];
  34. mouth.path = path.CGPath;
  35. mouth.fillColor = [UIColor clearColor].CGColor;
  36. mouth.strokeColor = [UIColor whiteColor].CGColor;
  37. mouth.position = CGPointMake(x, y);
  38. [self.view.layer addSublayer:mouth];
  39. }
  40.  
  41. for (int i=0; i<60; i++) {
  42.  
  43. float x = arc4random() % 300 + 10;
  44. float y = arc4random() % 500 + 100;
  45.  
  46. CALayer *dot = [CALayer layer];
  47. dot.frame = CGRectMake(x, y, 10, 10);
  48. dot.cornerRadius = 5;
  49. dot.backgroundColor = [UIColor whiteColor].CGColor;
  50. [self.view.layer addSublayer:dot];
  51. }
  52.  
  53. }
  54.  
  55. - (void)createSmilePullTab {
  56. UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:30 startAngle:0 endAngle:2.0 * M_PI clockwise:YES];
  57. UIView *tab = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.view.bounds) - 10, CGRectGetMidY(self.view.bounds) + 100, 100, 60)];
  58. tab.backgroundColor = [UIColor colorWithHue:0.2 saturation:0.8 brightness:0.5 alpha:1];
  59. [self.view addSubview:tab];
  60.  
  61. CAShapeLayer *circle = [CAShapeLayer layer];
  62. circle.path = path.CGPath;
  63. circle.fillColor = tab.backgroundColor.CGColor;
  64. circle.position = CGPointMake(0, 30);
  65. [tab.layer addSublayer:circle];
  66.  
  67. UIBezierPath *sPath = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:20 startAngle:M_PI * 0.3 endAngle:M_PI * 0.7 clockwise:YES];
  68.  
  69. CAShapeLayer *mouth = [CAShapeLayer layer];
  70. mouth.position = CGPointMake(50, 30);
  71. mouth.path = sPath.CGPath;
  72. mouth.fillColor = [UIColor clearColor].CGColor;
  73. mouth.strokeColor = [UIColor whiteColor].CGColor;
  74. [tab.layer addSublayer:mouth];
  75.  
  76. UIBezierPath *ePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(-20, -10) radius:5 startAngle:0 endAngle:2.0 * M_PI clockwise:NO];
  77. [ePath appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(20, -10) radius:5 startAngle:0 endAngle:2.0 * M_PI clockwise:NO]];
  78.  
  79. CAShapeLayer *eyes = [CAShapeLayer layer];
  80. eyes.path = ePath.CGPath;
  81. eyes.fillColor = [UIColor whiteColor].CGColor;
  82. eyes.position = mouth.position;
  83. [tab.layer addSublayer:eyes];
  84.  
  85. self.smilePullTab = tab;
  86. }
  87.  
  88. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  89. [UIView animateWithDuration:0.5 animations:^{
  90. self.smilePullTab.transform = CGAffineTransformMakeTranslation(-80, 0);
  91. }];
  92. }
  93.  
  94. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement