中心缩放的实时 iPhone 相机视图,“CGAffineTransformTranslate”不工作

发布于 2024-08-17 06:55:43 字数 525 浏览 6 评论 0原文

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

    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);

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

谢谢。

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 following code below:

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

But all I got was a scaled 1/2 sized view on the top left of the screen. It seems as though "CGAffineTransformTranslate" does nothing at all. The translation didn't work even when I used:

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

The translation portion seems to have no effect on the live camera view.
Hope someone can enlighten me.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

二货你真萌 2024-08-24 06:55:43

我也在同一条船上。我所做的就是物理移动拾取器框架。

[picker.view setFrame:CGRectMake(xOffset,yOffset,picker.view.frame.size.width,picker.view.frame.size.height)];

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)];
一梦等七年七年为一梦 2024-08-24 06:55:43

我一直在为同样的问题而苦苦挣扎。我已经确认缩放和旋转预览有效,但翻译似乎被忽略。我推测设置变换时 CGAffineTransform 的 tx, ty 部分将被忽略。这是 iPhone OS v3.1.2 的情况。我现在没有其他操作系统版本可供测试。

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.

薄暮涼年 2024-08-24 06:55:43

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

- (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.
}

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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文