在imageview中调整线条以适应我们的头部 [英] Adjusting the line to fit our head in imageview

查看:98
本文介绍了在imageview中调整线条以适应我们的头部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing one application same as HairTryOn all things are done. but problem is display in following image. i want to set hair style as per customer face using blue line as per display in image. i used the following code

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

此代码调整完整视图的大小。但我想只调整那些被手指移动的部分。

This code Resizing full view. but i want to Resize only those part which is moved by finger.

推荐答案

我看不出你的原语是如何构建的。但是您需要根据触摸区域划分您的点集,然后根据需要进行缩放。如果将线条转换为贝塞尔曲线,则操作曲线将更容易,因为您无需对形状进行大量调整,只需进行少量修改即可。

I don't see how your primitives are constructed. But you will need to partition your point set according to touch zones and scale then as needed. If you convert your lines into Bezier curves, then manipulating the curve will be easier, as you will not need to do terrible amount of adjustment to the shape with a small modifications.

这篇关于在imageview中调整线条以适应我们的头部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆