2013-03-14 9 views
10

Pracuję nad jedną aplikacją jak w HairTryOn, wszystkie rzeczy są zrobione. ale problem jest wyświetlany na poniższym obrazie. Chcę ustawić fryzurę według twarzy klienta za pomocą niebieskiej linii, jak na obrazie. kiedyś Następujący kodDopasowywanie linii do naszej głowy w widoku obrazu

testVw = [[UIView alloc]initWithFrame:CGRectMake(100,100, 100, 100)]; 
    testVw.backgroundColor = [UIColor clearColor]; 
    [self.view addSubview:testVw];  


    resizeVw = [[UIImageView alloc]initWithFrame:CGRectMake(testVw.frame.size.width-25, testVw.frame.size.height-25, 25, 25)]; 
    resizeVw.backgroundColor = [UIColor clearColor]; 
    resizeVw.userInteractionEnabled = YES; 
    resizeVw.image = [UIImage imageNamed:@"button_02.png" ]; 

    [testVw addSubview:resizeVw]; 

    UIPanGestureRecognizer* panResizeGesture = [[UIPanGestureRecognizer alloc] 
    initWithTarget:self action:@selector(resizeTranslate:)]; 

    [testVw addGestureRecognizer:panResizeGesture]; 

The resizeTranslate: metody:

-(void)resizeTranslate:(UIPanGestureRecognizer *)recognizer 
{ 
     if ([recognizer state]== UIGestureRecognizerStateBegan) 
     { 
      prevPoint = [recognizer locationInView:testVw.superview]; 
      [testVw setNeedsDisplay]; 
     } 
     else if ([recognizer state] == UIGestureRecognizerStateChanged) 
     { 
      if (testVw.bounds.size.width < 20) 
      { 

       testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, 20,testVw.bounds.size.height); 
       imgvw.frame = CGRectMake(12, 12, testVw.bounds.size.width-24, testVw.bounds.size.height-27); 
       resizeVw.frame =CGRectMake(testVw.bounds.size.width-25, testVw.bounds.size.height-25, 25, 25); 
       rotateVw.frame = CGRectMake(0, testVw.bounds.size.height-25, 25, 25); 
       closeVw.frame = CGRectMake(0, 0, 25, 25);    
      } 

      if(testVw.bounds.size.height < 20) 
      { 
       testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, testVw.bounds.size.width, 20); 
       imgvw.frame = CGRectMake(12, 12, testVw.bounds.size.width-24, testVw.bounds.size.height-27); 
       resizeVw.frame =CGRectMake(testVw.bounds.size.width-25, testVw.bounds.size.height-25, 25, 25); 
       rotateVw.frame = CGRectMake(0, testVw.bounds.size.height-25, 25, 25); 
       closeVw.frame = CGRectMake(0, 0, 25, 25); 
      } 

      CGPoint point = [recognizer locationInView:testVw.superview]; 
      float wChange = 0.0, hChange = 0.0; 

      wChange = (point.x - prevPoint.x); //Slow down increment 
      hChange = (point.y - prevPoint.y); //Slow down increment 


      testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, testVw.bounds.size.width + (wChange), testVw.bounds.size.height + (hChange)); 
      imgvw.frame = CGRectMake(12, 12, testVw.bounds.size.width-24, testVw.bounds.size.height-27); 

      resizeVw.frame =CGRectMake(testVw.bounds.size.width-25, testVw.bounds.size.height-25, 25, 25); 
      rotateVw.frame = CGRectMake(0, testVw.bounds.size.height-25, 25, 25); 
      closeVw.frame = CGRectMake(0, 0, 25, 25); 

      prevPoint = [recognizer locationInView:testVw.superview]; 

      [testVw setNeedsDisplay]; 
    } 
    else if ([recognizer state] == UIGestureRecognizerStateEnded) 
    { 
     prevPoint = [recognizer locationInView:testVw.superview]; 
     [testVw setNeedsDisplay]; 
    } 
} 

Kod zmiana rozmiaru powiększyć. ale chcę zmienić rozmiar tylko tej części, która jest przesuwana palcem. enter image description here

+0

czy możesz dać mi odpowiedź? –

+1

O co, dokładnie, pytasz? Widzę dużo kodu, ale nie ma jednoznacznego pytania! – Adam

+0

ok, nie wiemy, jak stworzyć ten efekt. Zainstaluj aplikację HairTryOn na iPhone'a. i zobacz efekt fryzury. również [see] (http://stackoverflow.com/questions/15701125/split-the-image-into-a-mesh-of-small-quadrangles-in-opengles) –

Odpowiedz

2

Nie widzę, jak konstruowane są twoje prymitywy. Musisz jednak podzielić swój zestaw punktów według stref dotyku i skalować go w razie potrzeby. Jeśli zamienisz linie na krzywe Beziera, manipulowanie krzywą będzie łatwiejsze, ponieważ nie będziesz musiał wykonywać straszliwej regulacji kształtu przy niewielkich modyfikacjach.

+0

dowolny przykładowy kod? –

Powiązane problemy