Trong ứng dụng của tôi, tôi muốn người dùng có thể chụp ảnh hoặc sử dụng ảnh từ thư viện ảnh. Khi người dùng nhấp vào nút tôi đã thực hiện chế độ xem cảnh báo bật lên, người dùng có thể chọn giữa chụp ảnh mới hoặc ảnh từ thư viện ảnh. Đây là mã tôi đã sử dụng:Tại sao giao diện máy ảnh của tôi hoạt động lạ khi tôi sử dụng UIImagePickerController?
- (void)PictureAlert:(id)sender {
UIAlertView *AlertDialog;
// Setting up AlertDialog.
AlertDialog = [[UIAlertView alloc] initWithTitle:nil
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Choose From Library", @"Take New Picture", nil];
[AlertDialog show]; }
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *ButtonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([ButtonTitle isEqualToString:@"Choose From Library"]) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// Pick photo.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
} else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// Setting up AlertDialog.
UIAlertView *AlertDialog;
AlertDialog = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[AlertDialog show];
}
} else if ([ButtonTitle isEqualToString:@"Take New Picture"]) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Take new photo.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.wantsFullScreenLayout = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
} else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Setting up AlertDialog.
UIAlertView *AlertDialog;
AlertDialog = [[UIAlertView alloc] initWithTitle:@"Error accessing camera"
message:@"Device does not support a camera"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[AlertDialog show];
}
}
}
Vấn đề là nếu người dùng muốn chụp một bức ảnh mới giao diện camera bật lên, và sau đó nếu bạn xoay thiết bị giao diện trông như thế này:
Và sau đó khi người dùng xoay nó lại nó đột nhiên trông như thế này:
một vấn đề bên ít là máy ảnh mất nhiều thời gian để tải.
Bất kỳ suy nghĩ sẽ được đánh giá :)
tôi đang gặp phải vấn đề này. – nicholjs