Scaled live iPhone Camera view in center, “CGAffineTransformTranslate” not working

前端 未结 3 1250
迷失自我
迷失自我 2020-12-15 12:44

I have a little problem which I could not solve. I really hope someone can help me with that. I wanted to resize the live camera view and place it in the center, using the f

相关标签:
3条回答
  • 2020-12-15 13:20

    I got solution. It must be set on message:

    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    

    Sample code:

    #pragma mark -
    #pragma mark UINavigationControllerDelegate
    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {   
        CGFloat width = [[self view] bounds].size.width;
        CGFloat height = width/4*3;
        CGSize sizeOfCamera = CGSizeMake(width, height);
        CGAffineTransform t = CGAffineTransformMakeScale(0.5, 0.5);
        [picker setCameraViewTransform:t];
    
        // Now the image is automatically aligned to center.
        // Translation matrix also can be applied, but didn't use because it's already aligned to center.
    }
    
    0 讨论(0)
  • 2020-12-15 13:23

    I was in the same boat. What I did was physically move the picker frame.

    [picker.view setFrame:CGRectMake(xOffset,yOffset,picker.view.frame.size.width,picker.view.frame.size.height)];
    
    0 讨论(0)
  • 2020-12-15 13:33

    I've been banging my head against the same problem. I have confirmed that scaling and rotating the preview works, but translations appear to be ignored. I would speculate that the tx, ty portions of the CGAffineTransform are being ignored when the transform is set. This is with iPhone OS v3.1.2. I don't have other OS versions to test against right now.

    0 讨论(0)
提交回复
热议问题