Tôi đang làm việc trên một ứng dụng máy ảnh mà tôi đang phải hiển thị một camera bên Setting cameraViewTransform động dành cho iOS 8
Tôi đang sử dụng camView.cameraViewTransform = CGAffineTransformMakeScale(1.0, 1.0) ;
nhưng nhận được kết quả khác nhau cho các thiết bị khác nhau và một thanh màu đen ở giữa thanh tab và Máy ảnh. Nếu tôi thay đổi giá trị của scaling
, máy ảnh sẽ bị thu phóng quá mức. Bất kỳ sự giúp đỡ nào trong vấn đề này sẽ rất được đánh giá cao.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self prepareCamera];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:NO];
[self launchCamera];
}
- (void)prepareCamera{
camView = [[UIImagePickerController alloc] init];
camView.delegate = self;
camView.sourceType = UIImagePickerControllerSourceTypeCamera;
camView.showsCameraControls = NO;
[self resizeCameraView];
}
- (void)resizeCameraView{
CGSize screenSize = self.view.bounds.size;
// set the aspect ratio of the camera
float heightRatio = 4.0f/3.0f;
// calculate the height of the camera based on the screen width
float cameraHeight = screenSize.width * heightRatio;
// calculate the ratio that the camera height needs to be scaled by
float scale = screenSize.height/cameraHeight;
// move the controller to the center of the screen
camView.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight)/2.0);
// concatenate the scale transform
camView.cameraViewTransform = CGAffineTransformScale(camView.cameraViewTransform, scale, scale);
}
- (void)launchCamera{
[camSubView addSubview:camView.view];
[camView viewWillAppear:YES];
[camView viewDidAppear:YES];
}
bạn có thể đăng một số mã về cách thiết lập chế độ xem camView không? – Istvan
@Istvan cảm ơn vì đã tra cứu, tôi đã cập nhật mã nguồn. –