iphone - 调整线条以适应 ImageView 中的头部

标签 iphone ios uiimageview uibezierpath bezier

我正在开发一个与 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];
    }
}

此代码调整全 View 大小。但我只想调整那些被手指移动的部分。 enter image description here

最佳答案

我不明白你的基元是如何构造的。但是您需要根据触摸区域对点集进行分区,然后根据需要进行缩放。如果您将线条转换为贝塞尔曲线,那么操纵曲线会更容易,因为您不需要通过小的修改对形状进行大量调整。

关于iphone - 调整线条以适应 ImageView 中的头部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402377/

相关文章:

iphone - 错误域 = SKErrorDomain 代码 = 2 "Cannot connect to iTunes Store"UserInfo = 0x6083900 {NSLocalizedDescription = 无法连接到 iTunes Store}

ios - 如何从服务器获取 JSON 对象(以相同的顺序)iPhone

ios - Iphone 4 和 Iphone 5 中的 UIView 问题

iOS:使用 AutoLayout 调整 UIImageView 的大小

swift - Swift 中的 UIView 方向更改

iphone - UIImagePickerController.frame 未全屏

iphone - iOS 7 上的 UILabel 自动调整大小错误

iphone - 本地通知声音不起作用

ios - 如何放大远距离录制的声音

ios - 如何根据用户设备从图像盒中选择图像