Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

camera - iOS UIImagePickerController, set frame

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 (just like Facetime/Skype does)

and show the front/rear (doesn't matter) camera stream.

Here's my code, for some reason, setFrame is not working!

self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.view.frame = CGRectMake(600, 400, 200, 200); // NOT WORKING !!!
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = NO;
self.picker.delegate = delegate;

[self presentViewController:self.picker animated:YES completion:nil];
  1. I've looked at similar SO topics but they all talk about how to

    set a view on top of the UIImagePickerController, not my problem at all.

  2. I've tried adding self.picker to a custom UIView sized 200 x 200 but still

    no success.

What am i doing wrong here?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...