Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 添加的照片不适合UIImageView的框架_Ios_Objective C_Uiimageview_Photo_Xcode5 - Fatal编程技术网

Ios 添加的照片不适合UIImageView的框架

Ios 添加的照片不适合UIImageView的框架,ios,objective-c,uiimageview,photo,xcode5,Ios,Objective C,Uiimageview,Photo,Xcode5,请帮助在UIImageView的框架中推送添加的照片。这张照片放不进相框。我在《IOS编程:大书呆子牧场指南》第12章“相机”中也做了同样的事情。添加照片之前:添加之后:我尝试了UIImageView的setContentMode,但不起作用。这是我的代码: #pragma mark UIActionSheetDelegate - (IBAction)displayActionSheet:(id)sender { UIActionSheet *actionSheet = [[UIAct

请帮助在UIImageView的框架中推送添加的照片。这张照片放不进相框。我在《IOS编程:大书呆子牧场指南》第12章“相机”中也做了同样的事情。添加照片之前:添加之后:我尝试了UIImageView的
setContentMode
,但不起作用。这是我的代码:

#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];
}

我的“加号”或“添加”按钮使用对话框调用操作表,因此我从图库中选择照片,结果与第二个屏幕截图类似。

设置图像视图属性:

imageView.clipsToBounds = YES;
imageView.contentMode = UIViewContentModeScaleAspectFill;

这两个都可以在Interface Builder中设置。

因此我发现了一行让我感到不安的代码,这都是因为我在表格视图中放置了自定义单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    if (indexPath.row == 0) {
        photoView = (UIImageView *)[photoCell viewWithTag:1]; // this is the first custom cell in my tableview and this line which I put on the model of the book isn't needed
        cell = photoCell;
...............................

photoView
真的是UIImageView吗?是的,
UIImageView*photoView第二个屏幕截图:这是你吗?photoView的框架是什么?你是如何将photoView添加到视图层次结构的?它的superview是什么?不起作用,在
-(void)imagePickerController:(UIImagePickerController*)中设置了属性并添加了代码。picker未完成PickingMediaWithInfo:(NSDictionary*)信息