Advertisement
Guest User

Untitled

a guest
May 28th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.58 KB | None | 0 0
  1. //
  2. // ExpoViewController.m
  3. // bozar
  4. //
  5. // Created by lennert van sever on 21/05/15.
  6. // Copyright (c) 2015 lennert van sever. All rights reserved.
  7. //
  8.  
  9. #import "ExpoViewController.h"
  10. #import "Cirkel.h"
  11. #import "HetAlgoritme.h"
  12. #import "DetailViewController.h"
  13. #import <QuartzCore/QuartzCore.h>
  14. #import "tabBarControl.h"
  15. @interface ExpoViewController ()
  16.  
  17. @property UIView *circleViewUser;
  18. @property UIView *testStuk4;
  19.  
  20. @property Cirkel *user;
  21.  
  22.  
  23. @property NSMutableArray *cirkleArray;
  24. @property UIImageView *plattegrond;
  25.  
  26. @property CGFloat xScherm;
  27. @property NSTimer *myTimer;
  28. @property (weak, nonatomic) IBOutlet UIButton *voorButton;
  29. @property (weak, nonatomic) IBOutlet UIButton *achterButton;
  30. @property (weak, nonatomic) IBOutlet UIButton *linksButton;
  31. @property (weak, nonatomic) IBOutlet UIButton *rechtsButton;
  32. @property CGFloat yScherm;
  33. @property CGFloat posX;
  34. @property CGFloat posY;
  35.  
  36. @property CGFloat stukPosX;
  37. @property CGFloat stukPosY;
  38.  
  39. @property float grootteC;
  40. @property float eersteGrootteC;
  41.  
  42. @property NSMutableArray *posXcirkels;
  43. @property NSMutableArray *posYcirkels;
  44. @property NSMutableArray *ratio;
  45.  
  46.  
  47. @property CAShapeLayer *lineShape;
  48. @property CAShapeLayer *lineShape2;
  49. @property CGMutablePathRef linePath;
  50. @property double posx;
  51. @property double posy;
  52. @property double d;
  53.  
  54. @property double posx2;
  55. @property double posy2;
  56. @property double d2;
  57.  
  58. @property double posx3;
  59. @property double posy3;
  60. @property double d3;
  61.  
  62.  
  63.  
  64. @end
  65.  
  66.  
  67. @implementation ExpoViewController
  68.  
  69.  
  70. #define CGRectSetPos( r, x, y ) CGRectMake( x, y, r.size.width, r.size.height )
  71. - (void)viewDidLoad {
  72. [super viewDidLoad];
  73. tabBarControl *tabBar = (tabBarControl *)self.tabBarController;
  74.  
  75. NSLog(@"expo id: %d", tabBar.expoId);
  76. self.cirkleArray = [[NSMutableArray alloc] init];
  77.  
  78. CGRect screenRect = [[UIScreen mainScreen] bounds]; //maakt een rect van het scherm
  79.  
  80. self.xScherm = screenRect.size.width; //breedte totaal scherm
  81. self.yScherm = screenRect.size.height; //hoogte scherm
  82.  
  83. UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  84. activityIndicator.center = CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0);
  85. [self.view addSubview: activityIndicator];
  86.  
  87. [activityIndicator startAnimating];
  88.  
  89.  
  90. NSURLSession *startJSON = [NSURLSession sharedSession];
  91. NSString *urlJson = [NSString stringWithFormat:@"http://iwtsl.ehb.be/~glen.van.haver/Bozar/kunstwerkenExpositieJSON.php?expositieId=%d", tabBar.expoId];
  92. [[startJSON dataTaskWithURL:[NSURL URLWithString:urlJson]
  93. completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  94. NSDictionary* json = [NSJSONSerialization
  95. JSONObjectWithData:data
  96. options:kNilOptions
  97. error:&error];
  98.  
  99.  
  100. dispatch_async(dispatch_get_main_queue(), ^{
  101.  
  102. for(int i = 0; i < [json count]; i++){
  103. NSString *selectie = [NSString stringWithFormat:@"kunstwerk%d", i];
  104. NSDictionary *expositieAll = [json objectForKey:selectie];
  105.  
  106. NSString *kunstId = [expositieAll objectForKey:@"kunstwerkId"];
  107. NSString *kunstPosX = [expositieAll objectForKey:@"kunstwerkLatitude"];
  108. NSString *kunstPosY = [expositieAll objectForKey:@"kunstwerkLongitude"];
  109. NSString *kunstAfbeelding = [expositieAll objectForKey:@"kunstwerkFoto"];
  110. NSString *kunstKleur = [expositieAll objectForKey:@"kunstwerkZaalKleur"];
  111.  
  112.  
  113.  
  114. NSLog(@"%@", [self colorFromHexString:kunstKleur]);
  115. Cirkel *cirkelObject = [[Cirkel alloc] init];
  116. cirkelObject.cirkelId = [kunstId intValue];
  117. cirkelObject.posXcirkel = self.xScherm/2+[kunstPosX floatValue]*(self.xScherm/4);
  118. cirkelObject.posYcirkel = self.yScherm/2-[kunstPosY floatValue]*(self.xScherm/4);
  119. cirkelObject.grootte = 20;
  120. cirkelObject.kleur = [UIColor whiteColor];
  121. cirkelObject.ani = YES;
  122. cirkelObject.toe = YES;
  123. cirkelObject.padAfbeedling = [NSString stringWithFormat:@"http://iwtsl.ehb.be/~glen.van.haver/Bozar/img/kunstwerken/%@", kunstAfbeelding];
  124. cirkelObject.kleurBorder = [self colorFromHexString:kunstKleur];
  125.  
  126.  
  127.  
  128. [self.cirkleArray addObject:cirkelObject];
  129.  
  130. }
  131.  
  132.  
  133.  
  134. [activityIndicator removeFromSuperview];
  135.  
  136. self.posXcirkels = [[NSMutableArray alloc] init];
  137. self.ratio = [[NSMutableArray alloc] init];
  138. self.posYcirkels = [[NSMutableArray alloc] init];
  139. self.grootteC = 1;
  140.  
  141.  
  142. self.posX = self.xScherm/2-50/2;
  143. self.posY = self.yScherm/2-50/2;
  144.  
  145. NSLog(@"count %lu", (unsigned long)[self.cirkleArray count]);
  146. for (int i = 0; i<[self.cirkleArray count]; i++) {
  147. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  148. UIView *itNaam = [itObject cirkelNaam];
  149. itNaam = [self dynamischeCirkel:[itObject posXcirkel] positieY:[itObject posYcirkel] grootte:[itObject grootte] kleur:[itObject kleur] kleurBorder:[itObject kleurBorder] afbeeldingNaam:[itObject padAfbeedling] variabeleNaam:itNaam metAnimatie:[itObject ani] meteenToevoegen:[itObject toe] nrCirkel:i cirkelId:[itObject cirkelId]];
  150. itObject.cirkelNaam = itNaam;
  151.  
  152. }
  153.  
  154. });
  155.  
  156. }] resume];
  157.  
  158. self.user = [[Cirkel alloc] init];
  159. self.user.cirkelId = -1;
  160. self.user.cirkelNaam = self.circleViewUser;
  161. self.user.posXcirkel = self.xScherm/2;//+30;
  162. self.user.posYcirkel = self.yScherm/2;//+30;
  163. self.user.grootte = 20;
  164. self.user.kleur = [self colorFromHexString:@"#48CFAD"];
  165. self.user.ani = YES;
  166. self.user.toe = YES;
  167. self.user.kleurBorder = nil;
  168.  
  169. NSLog(@"%f", self.xScherm/350);
  170. self.plattegrond = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plattegrond belgie.png"]];
  171. self.plattegrond.transform = CGAffineTransformMakeScale(self.xScherm/400,self.xScherm/400);
  172. self.plattegrond.center = CGPointMake(self.xScherm/2+10*(self.xScherm/4), self.yScherm/2-8.5*(self.xScherm/4));
  173. [self.view addSubview:self.plattegrond];
  174.  
  175.  
  176.  
  177.  
  178. //self.circleViewUser = [[UIView alloc] initWithFrame:CGRectMake(self.xScherm/2-50/2,self.yScherm/2-50/2,50,50)];
  179. self.user.cirkelNaam = [self cirkel:self.user.posXcirkel positieY:self.user.posYcirkel grootte:self.user.grootte kleur:self.user.kleur kleurBorder:self.user.kleurBorder afbeeldingNaam:nil variabeleNaam:self.user.cirkelNaam metAnimatie:self.user.ani meteenToevoegen:self.user.toe kunstWerk:NO nrCirkel:-1 cirkelId:-1];
  180. }
  181.  
  182.  
  183. - (UIColor *)colorFromHexString:(NSString *)hexString { //http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string helemaal overgenomen. Om van hex naar UIColor te gaan
  184. unsigned rgbValue = 0;
  185. NSScanner *scanner = [NSScanner scannerWithString:hexString];
  186. [scanner setScanLocation:1]; // bypass '#' character
  187. [scanner scanHexInt:&rgbValue];
  188. return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
  189. }
  190.  
  191. -(UIView*)dynamischeCirkel:(float)posX positieY:(float)posY grootte:(int)bCirkel kleur:(UIColor*)kleur kleurBorder:(UIColor*)border afbeeldingNaam:(NSString *)img variabeleNaam:(UIView*)varC metAnimatie:(BOOL)ani meteenToevoegen:(BOOL)toe nrCirkel:(int)nr cirkelId:(int)id {
  192. float schuineZijde = sqrt(((posX-self.posX)*(posX-self.posX)+(posY-self.posY)*(posY-self.posY))); //pythagoras!!
  193. float ratioC = (500-schuineZijde)/5; //grootte berekenen afhankelijk van de afstand tussen de gebruiker
  194.  
  195. if(ratioC < 0){
  196. ratioC = 0;
  197. }
  198. Cirkel *deze = [self.cirkleArray objectAtIndex:nr];
  199. /*if(posX > -50 && posY > -50 && posX < self.xScherm+50 && posY < self.xScherm+50){
  200. deze.grootte = ratioC; //de breedte zetten die net is aangepast
  201. }
  202. else{*/
  203. ratioC = 50;
  204. deze.grootte = ratioC;
  205. //}
  206. deze.posXcirkel = posX-ratioC/2;
  207. deze.posYcirkel = posY-ratioC/2;
  208.  
  209. // NSLog(@"ratio %f", ratioC);
  210. return [self cirkel:posX positieY:posY grootte:ratioC kleur:kleur kleurBorder:border afbeeldingNaam:img variabeleNaam:varC metAnimatie:ani meteenToevoegen:toe kunstWerk:YES nrCirkel:nr cirkelId:id];
  211. }
  212.  
  213. -(UIView*)cirkel:(float)posX positieY:(float)posY grootte:(int)bCirkel kleur:(UIColor*)kleur kleurBorder:(UIColor*)border afbeeldingNaam:(NSString *)img variabeleNaam:(UIView*)varC metAnimatie:(BOOL)ani meteenToevoegen:(BOOL)toe kunstWerk:(BOOL)kunst nrCirkel:(int)nr cirkelId:(int)id{
  214. varC = [[UIView alloc] initWithFrame:CGRectMake(posX-bCirkel/2,posY-bCirkel/2,bCirkel,bCirkel)]; //de variabele zorgen dat hij op elke device perfect in het midden staat.
  215. varC.alpha = 1;
  216. varC.layer.cornerRadius = bCirkel/2; //zorgt ervoor om de
  217. varC.backgroundColor = kleur;
  218. if(kunst){
  219. varC.layer.masksToBounds = NO;
  220. varC.layer.shadowOffset = CGSizeMake(2, 2);
  221. varC.layer.shadowRadius = 2;
  222. varC.layer.shadowOpacity = 0.7; //http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview om een shadow te tekenen
  223. }
  224. if(ani){
  225. varC.transform = CGAffineTransformMakeScale(0,0);
  226. }
  227. if(toe){
  228. [self.view addSubview:varC];
  229. }
  230. if(kunst){
  231.  
  232. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
  233. initWithTarget:self action:@selector(processTap:)];
  234.  
  235. [varC setTag:id]; //set tag value
  236. [varC addGestureRecognizer:tap];
  237. [varC setUserInteractionEnabled:YES];
  238.  
  239. UIImageView *imageHolder = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, bCirkel, bCirkel)];
  240.  
  241. NSURL *url = [NSURL URLWithString:img];
  242.  
  243. NSData *data = [NSData dataWithContentsOfURL:url];
  244. UIImage *image = [UIImage imageWithData:data];
  245. imageHolder.image = image;
  246. imageHolder.clipsToBounds = YES;
  247. imageHolder.layer.cornerRadius = bCirkel/2;
  248. imageHolder.transform = CGAffineTransformMakeScale(0.85,0.85); //afbeelding kleiner maken
  249.  
  250. UIView *borderCirkel = [[UIView alloc] initWithFrame:CGRectMake(0,0,bCirkel,bCirkel)];
  251. borderCirkel.layer.cornerRadius = bCirkel/2;
  252. borderCirkel.backgroundColor = [UIColor clearColor];
  253. borderCirkel.layer.borderColor = border.CGColor;
  254. borderCirkel.layer.borderWidth = 1.5;
  255. borderCirkel.transform = CGAffineTransformMakeScale(0.95,0.95);
  256.  
  257. [varC addSubview:borderCirkel];
  258. [varC addSubview:imageHolder];
  259. }
  260. self.eersteGrootteC = bCirkel/2;
  261. return varC;
  262. }
  263. - (void)processTap:(UIGestureRecognizer *)sender //http://stackoverflow.com/questions/11148415/how-to-pass-argument-to-action-in-uigesturerecognizer-initwithtarget-action voor de tab op de view
  264. {
  265. // NSLog(@"tabbed!!");
  266. // NSLog(@"%ld", (long)sender.view.tag);
  267. sender.view.layer.zPosition = 5;
  268. [UIView animateWithDuration:.5 animations:^{
  269.  
  270. //sender.view.layer.cornerRadius = 0;
  271.  
  272. NSArray *childViews = [sender.view subviews];
  273. for(int i = 0; i < [childViews count]; i++){
  274. UIView *childView = [childViews objectAtIndex:i];
  275. childView.transform = CGAffineTransformMakeScale(.1,.1);
  276.  
  277. }
  278. sender.view.transform = CGAffineTransformMakeScale(40,40);
  279. sender.view.clipsToBounds = NO;
  280.  
  281. } completion:^(BOOL finished){
  282. DetailViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
  283. viewController.kunstId = (int)sender.view.tag;
  284. [self.navigationController pushViewController:viewController animated:NO];
  285.  
  286. sender.view.layer.zPosition = 1;
  287. NSArray *childViews = [sender.view subviews];
  288. for(int i = 0; i < [childViews count]; i++){
  289.  
  290. UIView *childView = [childViews objectAtIndex:i];
  291. if(i == 1){
  292. childView.transform = CGAffineTransformMakeScale(.85,.85);
  293. }
  294. else{
  295. childView.transform = CGAffineTransformMakeScale(.90,.90);
  296. }
  297.  
  298. }
  299.  
  300. }];
  301.  
  302. }
  303.  
  304. /*- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  305. NSLog(@"segue");
  306. }
  307. */
  308. - (void)viewDidAppear:(BOOL)animated{
  309. [UIView animateWithDuration:1 animations:^{
  310.  
  311. self.user.cirkelNaam.transform = CGAffineTransformMakeScale(1,1);
  312.  
  313. for (int i = 0; i<[self.cirkleArray count]; i++) {
  314. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  315. UIView *itNaam = [itObject cirkelNaam];
  316.  
  317. itNaam.transform = CGAffineTransformMakeScale(1,1);
  318. }
  319. } completion:^(BOOL finished){
  320. self.lineShape.lineWidth = 1;
  321. CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
  322. pathAnimation.duration = 1.0f;
  323. pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
  324. pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
  325. [self.lineShape addAnimation:pathAnimation forKey:@"strokeEnd"]; //http://stackoverflow.com/questions/15651717/how-to-animate-cashapelayer-path-and-fillcolor voor de animatie
  326. //http://stackoverflow.com/questions/5370557/draw-line-using-cgcontext hoe een lijn te tekenen
  327.  
  328. }];
  329.  
  330.  
  331. }
  332.  
  333. - (void)viewWillDisappear:(BOOL)animated{
  334. [UIView animateWithDuration:1 animations:^{ //http://www.raywenderlich.com/2454/uiview-tutorial-for-ios-how-to-use-uiview-animation om animatie te gebruiken.
  335. self.circleViewUser.transform = CGAffineTransformMakeScale(0,0);
  336. for (int i = 0; i<[self.cirkleArray count]; i++) {
  337. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  338. UIView *itNaam = [itObject cirkelNaam];
  339. itNaam.transform = CGAffineTransformMakeScale(0,0);
  340. }
  341. } completion:^(BOOL finished){
  342. NSLog(@"%@", @"animatie gedaan");
  343. }];
  344. }
  345.  
  346. - (void)didReceiveMemoryWarning {
  347. [super didReceiveMemoryWarning];
  348. // Dispose of any resources that can be recreated.
  349. }
  350. -(void)handleZoom:(UIPinchGestureRecognizer *)recognizer{
  351. /*NSLog(@"schaal %f", [recognizer scale]);
  352. NSLog(@"Snelheid %f", [recognizer velocity]);
  353. for (int i = 0; i<[self.cirkleArray count]; i++) {
  354. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  355. UIView *itNaam = [itObject cirkelNaam];
  356. itNaam.transform = CGAffineTransformMakeScale([recognizer scale], [recognizer scale]);
  357. self.plattegrond.transform = CGAffineTransformMakeScale(self.plattegrond.transform.a+[recognizer velocity]/1000, self.plattegrond.transform.d+[recognizer velocity]/1000);
  358. }*/
  359. }
  360.  
  361. -(void)handleRotation:(UIRotationGestureRecognizer *)recognizer{
  362. // CGFloat snelheid = [recognizer velocity];
  363. CGFloat rotatie = [recognizer rotation];
  364. // NSLog(@"x: %f", snelheid);
  365. // NSLog(@"x: %f", self.xScherm/2+cos(rotatie));
  366. // self.view.transform=CGAffineTransformRotate(self.view.transform, rotatie);
  367. // NSLog(@"y: %f", self.yScherm/2+sin(rotatie)*100);
  368. for (int i = 0; i<[self.cirkleArray count]; i++) {
  369. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  370. UIView *itNaam = [itObject cirkelNaam];
  371.  
  372. float posXf = [[self.posXcirkels objectAtIndex:i] floatValue];
  373.  
  374. float posYf = [[self.posYcirkels objectAtIndex:i] floatValue];
  375.  
  376. float rotX = self.xScherm/2-25;
  377. float rotY = self.yScherm/2-25;
  378. float schuineZijde = sqrt(((posXf-rotX)*(posXf-rotX)+(posYf-rotY)*(posYf-rotY)));
  379.  
  380.  
  381. float angle = atan2(posYf-rotY, posXf-rotX);
  382.  
  383. float verplaatsingX = schuineZijde * cos(angle+rotatie/20) + rotX;
  384. float verplaatsingY = schuineZijde * sin(angle+rotatie/20) + rotY;
  385.  
  386.  
  387. float rotXI = self.xScherm/2;
  388. float rotYI = self.yScherm/2;
  389.  
  390. float schuineZijdeI = sqrt(((self.plattegrond.center.x-rotXI)*(self.plattegrond.center.x-rotXI)+(self.plattegrond.center.y-rotYI)*(self.plattegrond.center.y-rotYI)));
  391. float angleI = atan2(self.plattegrond.center.y-rotYI, self.plattegrond.center.x-rotXI);
  392.  
  393. float factorI = 140;
  394. float verplaatsingXI = schuineZijdeI * cos(angleI+rotatie/factorI) + rotXI;
  395. float verplaatsingYI = schuineZijdeI * sin(angleI+rotatie/factorI) + rotYI;
  396.  
  397. //NSLog(@"angle %f", angleI);
  398. NSLog(@"%f", schuineZijdeI);
  399.  
  400. posXf = verplaatsingX;
  401. posYf = verplaatsingY;
  402.  
  403. itNaam.frame = CGRectSetPos(itNaam.frame, posXf, posYf);
  404.  
  405. self.plattegrond.center = CGPointMake(verplaatsingXI, verplaatsingYI);
  406. self.plattegrond.transform = CGAffineTransformRotate(self.plattegrond.transform, rotatie/factorI);
  407.  
  408. [self.posXcirkels replaceObjectAtIndex:i withObject:[NSNumber numberWithFloat:posXf]];
  409. [self.posYcirkels replaceObjectAtIndex:i withObject:[NSNumber numberWithFloat:posYf]];
  410.  
  411. }
  412. /*[self.lineShape removeFromSuperlayer];
  413.  
  414. self.lineShape = nil;
  415. self.linePath = nil;
  416. self.linePath = CGPathCreateMutable();
  417. self.lineShape = [CAShapeLayer layer];
  418.  
  419. self.lineShape.lineWidth = 1;
  420. self.lineShape.lineCap = kCALineCapRound;
  421. self.lineShape.strokeColor = [[UIColor blackColor] CGColor];
  422. self.lineShape.fillColor = [[UIColor clearColor] CGColor];
  423.  
  424. float x = [[self.posXcirkels objectAtIndex:0] floatValue]; float y = [[self.posYcirkels objectAtIndex:0] floatValue];
  425. int toX = [[self.posXcirkels objectAtIndex:1] floatValue]; int toY = [[self.posYcirkels objectAtIndex:1] floatValue];
  426. int toX2 = [[self.posXcirkels objectAtIndex:2] floatValue]; int toY2 = [[self.posYcirkels objectAtIndex:2] floatValue];
  427.  
  428. CGPathMoveToPoint(self.linePath, NULL, x+20, y+20);
  429. CGPathAddLineToPoint(self.linePath, NULL, toX+30, toY+30);
  430. CGPathAddLineToPoint(self.linePath, NULL, toX+30, toY+30);
  431. CGPathAddLineToPoint(self.linePath, NULL, toX2+20, toY2+20);
  432.  
  433. self.lineShape.path = self.linePath;
  434. CGPathRelease(self.linePath);
  435. self.lineShape.zPosition = -1;
  436. [self.view.layer addSublayer:self.lineShape];*/
  437. }
  438.  
  439.  
  440.  
  441. - (void)handlePan:(UIPanGestureRecognizer *)recognizer{
  442. CGFloat snelheidX = [recognizer velocityInView:self.view].x;
  443. CGFloat snelheidY = [recognizer velocityInView:self.view].y;
  444.  
  445. recognizer.maximumNumberOfTouches = 1;
  446.  
  447. if([recognizer maximumNumberOfTouches] == 1){
  448. for (int i = 0; i<[self.cirkleArray count]; i++) {
  449. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  450. UIView *itNaam = [itObject cirkelNaam];
  451.  
  452. float posXf = [[self.posXcirkels objectAtIndex:i] floatValue];
  453.  
  454. // float snelheidAanpassenY = fabsf(((self.posX-posXf)/self.xScherm));
  455. float posYf = [[self.posYcirkels objectAtIndex:i] floatValue];
  456.  
  457. // float snelheidAanpassenX = fabsf(((self.posY-posYf)/self.yScherm));
  458. posXf += snelheidX/290;
  459. posYf += snelheidY/290;
  460. float schuineZijde;
  461. float ratioC = 0.0;
  462. float eersteRatio = 0.0;
  463. if(posXf > -50 && posYf > -50 && posXf < self.xScherm+50 && posYf < self.xScherm+50){
  464. schuineZijde = sqrt(((posXf-self.posX)*(posXf-self.posX)+(posYf-self.posY)*(posYf-self.posY))); //pythagoras!!
  465. ratioC = (self.yScherm-schuineZijde)/50; //grootte berekenen afhankelijk van de afstand tussen de gebruiker
  466. eersteRatio = [[self.ratio objectAtIndex:0] floatValue];
  467. }
  468.  
  469.  
  470.  
  471.  
  472. if(posXf > -50 && posYf > -50 && posXf < self.xScherm+50 && posYf < self.xScherm+50){
  473. //NSLog(@"controle %f", posXf);
  474.  
  475. itNaam.transform = CGAffineTransformMakeScale(ratioC/eersteRatio, ratioC/eersteRatio);
  476. }
  477. else{
  478.  
  479. itNaam.transform = CGAffineTransformMakeScale(1, 1);
  480. }
  481.  
  482. NSLog(@"%f", self.plattegrond.center.x);
  483. float erbijX = self.plattegrond.center.x + snelheidX/1990;
  484. float erbijY = self.plattegrond.center.y + snelheidY/1990;
  485.  
  486.  
  487. self.plattegrond.center = CGPointMake(erbijX, erbijY);
  488.  
  489. itNaam.frame = CGRectSetPos(itNaam.frame, posXf, posYf);
  490.  
  491. [self.posXcirkels replaceObjectAtIndex:i withObject:[NSNumber numberWithFloat:posXf]];
  492. [self.posYcirkels replaceObjectAtIndex:i withObject:[NSNumber numberWithFloat:posYf]];
  493. }
  494. /*[self.lineShape removeFromSuperlayer];
  495.  
  496. self.lineShape = nil;
  497. self.linePath = nil;
  498. self.linePath = CGPathCreateMutable();
  499. self.lineShape = [CAShapeLayer layer];
  500.  
  501. self.lineShape.lineWidth = 1;
  502. self.lineShape.lineCap = kCALineCapRound;
  503. self.lineShape.strokeColor = [[UIColor blackColor] CGColor];
  504. self.lineShape.fillColor = [[UIColor clearColor] CGColor];
  505.  
  506. float x = [[self.posXcirkels objectAtIndex:0] floatValue]; float y = [[self.posYcirkels objectAtIndex:0] floatValue];
  507. int toX = [[self.posXcirkels objectAtIndex:1] floatValue]; int toY = [[self.posYcirkels objectAtIndex:1] floatValue];
  508. int toX2 = [[self.posXcirkels objectAtIndex:2] floatValue]; int toY2 = [[self.posYcirkels objectAtIndex:2] floatValue];
  509.  
  510. CGPathMoveToPoint(self.linePath, NULL, x+20, y+20);
  511. CGPathAddLineToPoint(self.linePath, NULL, toX+30, toY+30);
  512. CGPathAddLineToPoint(self.linePath, NULL, toX+30, toY+30);
  513. CGPathAddLineToPoint(self.linePath, NULL, toX2+20, toY2+20);
  514.  
  515. self.lineShape.path = self.linePath;
  516. CGPathRelease(self.linePath);
  517. self.lineShape.zPosition = -1;
  518. [self.view.layer addSublayer:self.lineShape];*/
  519.  
  520. }
  521. }
  522.  
  523.  
  524. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  525. //self.posXcirkels = [[NSMutableArray alloc] init];
  526. //self.posYcirkels = [[NSMutableArray alloc] init];
  527.  
  528. for (int i = 0; i<[self.cirkleArray count]; i++) {
  529.  
  530. Cirkel *itObject = [self.cirkleArray objectAtIndex:i];
  531. //UIView *itNaam = [itObject cirkelNaam];
  532.  
  533. float posYcirkelAanpassen = [itObject posYcirkel];
  534. float posXcirkelAanpassen = [itObject posXcirkel];
  535.  
  536.  
  537. NSNumber *numX = [NSNumber numberWithFloat:posXcirkelAanpassen];
  538. [self.posXcirkels addObject:numX];
  539.  
  540. NSNumber *numY = [NSNumber numberWithFloat:posYcirkelAanpassen];
  541. [self.posYcirkels addObject:numY];
  542.  
  543. if(posYcirkelAanpassen > -50 && posXcirkelAanpassen > -50 && posYcirkelAanpassen < self.xScherm+50 && posXcirkelAanpassen < self.xScherm+50){
  544. float schuineZijde = sqrt(((posYcirkelAanpassen-self.posX)*(posYcirkelAanpassen-self.posX)+(posYcirkelAanpassen-self.posY)*(posYcirkelAanpassen-self.posY))); //pythagoras!!
  545. float ratioC = (self.yScherm-schuineZijde)/50;
  546. [self.ratio addObject:[NSNumber numberWithFloat:ratioC]];
  547. }
  548. }
  549. }
  550.  
  551.  
  552. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement