在imageview中调整线条以适合我们的头部

我正在开发一个与HairTryOn相同的应用程序。 但在下面的图像中显示问题。 我想根据客户的脸部设置发型,使用蓝色线条按照图像中的显示。 我用下面的代码

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

resizeTranslate:方法:

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

此代码调整全屏视图。 但是我只想调整那些被手指移动的部分。 在这里输入图像说明

我看不出你的原始人是如何build造的。 但是,您需要根据触摸区域划分您的点集,然后根据需要进行缩放。 如果将线条转换为贝塞尔曲线,则操作曲线将变得更加容易,因为您不需要稍微修改就可以对形状进行可怕的调整。