调整图像视图中的线条以适应我们的头部

10

我正在开发一个类似于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];
    }
}
这段代码在调整完整视图大小。但我只想调整手指移动的那部分。 enter image description here

你能给我答案吗? - SAMIR RATHOD
1
你到底在问什么?我看到了很多代码,但没有明确的问题! - Adam
好的,我们不知道如何创建这些效果。请安装HairTryOn iPhone应用程序并查看发型效果。同时,请参阅此链接:https://dev59.com/V3DXa4cB1Zd3GeqP-Uja - SAMIR RATHOD
1个回答

2

我不清楚你的基本单元是如何构造的。但是你需要根据触摸区域将点集进行分区,并根据需要进行缩放。如果你将线条转换为贝塞尔曲线,则操纵曲线会更容易,因为只需进行少量调整即可对形状进行修改。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接