请帮助将添加的照片推送到 UIImageView 的框架中。照片不适合相框。我在“IOS 编程:大书呆子牧场指南”第 12 章“相机”中做了同样的事情。添加照片前:https ://www.dropbox.com/s/o0uypvspuhvlkm2/Screen%20Shot%202013-10-27%20at%205.08.39%20PM.jpg添加后:https ://www.dropbox.com/ s/u6qffb1l941cb0v/Screen%20Shot%202013-10-27%20at%205.09.02%20PM.jpg我试过setContentMode
UIImageView - 不起作用。这是我的代码:
#pragma mark UIActionSheetDelegate
- (IBAction)displayActionSheet:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take photo", @"Choose photo from gallery", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
[self takePhoto];
break;
case 1:
[self choosePhoto];
break;
}
}
#pragma mark UIImagePickerControllerDelegate
- (void)takePhoto {
UIImagePickerController *pickerControllerTakePhoto = [[UIImagePickerController alloc] init];
[pickerControllerTakePhoto setSourceType:UIImagePickerControllerSourceTypeCamera];
[pickerControllerTakePhoto setDelegate:self];
[self presentViewController:pickerControllerTakePhoto animated:YES completion:nil];
}
- (void)choosePhoto {
UIImagePickerController *pickerControllerChoosePhoto = [[UIImagePickerController alloc] init];
[pickerControllerChoosePhoto setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[pickerControllerChoosePhoto setDelegate:self];
[self presentViewController:pickerControllerChoosePhoto animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *myPhoto = [info objectForKey:UIImagePickerControllerOriginalImage];
[photoView setImage:myPhoto];
[self dismissViewControllerAnimated:YES completion:NULL];
}
我的“加号”或“添加”按钮调用带有对话框的操作表,所以我从图库中选择照片,结果就像第二个屏幕截图一样。