iOS UIImagePickerController, set frame

前端 未结 2 1433
难免孤独
难免孤独 2020-12-18 13:17

I\'m trying to accomplish the following result:

Set the frame of my UIImagePickerController to, lets say 200 x 200,

Set my frame at the bottom-right corner (

相关标签:
2条回答
  • 2020-12-18 13:25

    You need to use the cameraViewTransform property of UIImagePicker to adjust its camera frame. This property accept any CGAffineTransform you made (e.g. scaling, rotating, inverting, translating, etc).

    For example, if you want to move the camera view down by 50 points and scale the camera view 1.2x its original size, this is how you'll do it:

        CGAffineTransform transform = CGAffineTransformMakeTranslation(0.0f, 50.0f);
        transform = CGAffineTransformScale(transform, 1.2f, 1.2f);
        imagePicker.cameraViewTransform = transform;
    
    0 讨论(0)
  • 2020-12-18 13:44

    From UIViewController reference link

    presentViewController:animated:completion:

    Discussion

    On iPhone and iPod touch, the presented view is always full screen

    If you want to embed image picker, you should manually add its view to one of your other views.

    like this

    [self.view addSubview:self.imagePickerController.view];
    

    I experimented with the code from my last post, and commented out the final scale transform ((the one which makes it full size) and I ended up with a lovely miniature camera imagePicker floating in the middle of my screen, so it definitely does work! The exact code I used, including the zoom/fade-in transition, is -

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    
    UIView *controllerView = imagePickerController.view;
    controllerView.alpha = 0.0;
    controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5);
    
    [[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView];
    
    [UIView animateWithDuration:0.3
              delay:0.0
            options:UIViewAnimationOptionCurveLinear
         animations:^{
             controllerView.alpha = 1.0;
         }
         completion:nil
    ];
    [imagePickerController release];
    
    0 讨论(0)
提交回复
热议问题