7

我有一个我无法解决的小问题。我真的希望有人可以帮助我。我想使用以下代码调整实时摄像机视图的大小并将其放置在中心:

    picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, 0.5, 0.56206);
    picker.cameraViewTransform = CGAffineTransformTranslate(picker.cameraViewTransform, 80, 120);

但我得到的只是屏幕左上角的 1/2 大小的视图。似乎“CGAffineTransformTranslate”什么也没做。即使我使用了以下翻译,也无法正常工作:

     picker.cameraViewTransform = CGAffineTransformMake(1, 0, 0, 1, 80, 120);

翻译部分似乎对实时摄像机视图没有影响。希望有人能启发我。

谢谢。

4

3 回答 3

5

我在同一条船上。我所做的是物理移动选择器框架。

[picker.view setFrame:CGRectMake(xOffset,yOffset,picker.view.frame.size.width,picker.view.frame.size.height)];
于 2012-02-27T00:29:46.443 回答
1

我一直在努力解决同样的问题。我已经确认缩放和旋转预览有效,但翻译似乎被忽略了。我推测在设置转换时会忽略 CGAffineTransform 的 tx、ty 部分。这适用于 iPhone OS v3.1.2。我现在没有其他操作系统版本可供测试。

于 2010-04-14T12:38:21.827 回答
-1

我得到了解决方案。必须在消息上设置:

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

示例代码:

#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.
}
于 2010-06-05T18:42:27.930 回答