2013-03-14 24 views
10

Tôi đang phát triển một ứng dụng giống như HairTryOn tất cả mọi thứ được thực hiện. nhưng vấn đề được hiển thị trong hình ảnh sau đây. tôi muốn thiết lập kiểu tóc theo khuôn mặt khách hàng bằng cách sử dụng đường màu xanh theo hiển thị trong hình ảnh. tôi sử dụng đoạn mã sauĐiều chỉnh đường thẳng để phù hợp với đầu của chúng tôi trong imageview

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]; 

Các resizeTranslate: phương pháp:

-(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]; 
    } 
} 

Mã này Thay đổi kích thước xem đầy đủ. nhưng tôi muốn thay đổi kích thước chỉ những phần được di chuyển bằng ngón tay. enter image description here

+0

bạn có thể trả lời cho tôi không? –

+1

Chính xác, bạn đang yêu cầu điều gì? Tôi thấy rất nhiều mã, nhưng không có câu hỏi rõ ràng! – Adam

+0

ok, chúng tôi không biết cách tạo hiệu ứng này. Vui lòng cài đặt ứng dụng HairTryOn trên iPhone. và xem hiệu ứng kiểu tóc. cũng [xem] (http://stackoverflow.com/questions/15701125/split-the-image-into-a-mesh-of-small-quadrangles-in-opengles) –

Trả lời

2

Tôi không thấy cách nguyên thủy của bạn được xây dựng. Nhưng bạn sẽ cần phải phân vùng thiết lập điểm của bạn theo vùng cảm ứng và quy mô sau đó khi cần thiết. Nếu bạn chuyển đổi đường của bạn thành đường cong Bezier, sau đó thao tác các đường cong sẽ được dễ dàng hơn, vì bạn sẽ không cần phải làm số lượng khủng khiếp của điều chỉnh hình dạng với một sửa đổi nhỏ.

+0

bất kỳ mã mẫu nào? –

Các vấn đề liên quan