English 中文(简体)
Scaled live iPhone Camera view in center, "CGAffineTransformTranslate" not working
原标题:

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.

问题回答

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

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.

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




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签