質問

I'm trying to invert my UIImagePickerController so that it is able to both fill the screen of an iPhone 5 and obviously, be inverted. Here is the code I have for the UIImagePickerController:

- (void)applicationDidBecomeActive
{

UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.cameraViewTransform = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
imageViewPickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0.0, 71.0);
imageViewPickerController.cameraViewTransform = CGAffineTransformScale(imageViewPickerController.cameraViewTransform, 1.333333, 1.333333);


[self presentViewController:imageViewPickerController
                   animated:NO
                 completion:NULL];


}

If I run this code, I don't get any inversion. If I modify it like so:

- (void)applicationDidBecomeActive
{

UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
    imageViewPickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0.0, 71.0);
imageViewPickerController.cameraViewTransform = CGAffineTransformScale(imageViewPickerController.cameraViewTransform, 1.333333, 1.333333);
imageViewPickerController.cameraViewTransform = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));


[self presentViewController:imageViewPickerController
                   animated:NO
                 completion:NULL];


}

it inverts, but only takes up a 320x320 square of the screen, disregarding my other transformations. If anyone could lend some expertise as to how to get it to follow all of these arguments, I would really appreciate it.

役に立ちましたか?

解決

You should try to concatenate all of the transformations you create into one transform and then set it as the cameraViewTransform like so:

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;

他のヒント

The following code works for me (for ios 6 and 7). But please notice that I add imagePickerController.view as subview of my placeholder view.

    CGSize screenSize = [UIScreen mainScreen].bounds.size;

    CGFloat cameraAspectRatio = 3.0f / 4.0f;

    CGFloat scale = (screenSize.height / screenSize.width) * cameraAspectRatio;

    CGFloat yOffset = (screenSize.height - screenSize.width / cameraAspectRatio) / 2.0;

    CGAffineTransform translate = CGAffineTransformMakeTranslation(0, yOffset);
    CGAffineTransform fullScreen = CGAffineTransformMakeScale(scale, scale);
    CGAffineTransform fullTranform = CGAffineTransformConcat(fullScreen, translate);

    if(SYSTEM_VERSION_LESS_THAN(@"7.0"))
    {
        CGRect rect = self.imagePickerController.view.frame;
        rect.size.height = screenSize.width / cameraAspectRatio;
        rect.size.width = screenSize.width;
        imagePickerController.view.frame = rect;

        imagePickerController.view.transform = fullTranform;
    }
    else
    {
        imagePickerController.view.frame = [UIScreen mainScreen].bounds;
        imagePickerController.cameraViewTransform = fullTranform;
    }

    [self.placeholder addSubview:imagePickerController.view];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top