将UIImage传递给第二个视图控制器滞后转换

时间:2011-04-17 16:31:23

标签: iphone objective-c ios uiimageview uiimagepickercontroller

我正在使用UIImagePickerController从我的相册中选择一张图片。一旦我选择了图像,我就将图像传递给第二个视图控制器并将其显示在UIImageView中。请参阅以下代码:

第一个视图控制器:

- (IBAction)selectPhoto
{
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:self.imagePicker animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{    
    UploadViewController *uploadViewController = [[UploadViewController alloc] initWithNibName:@"UploadViewController" bundle:nil];
    [uploadViewController setImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];

    [picker pushViewController:uploadViewController animated:YES];
}

第二个视图控制器:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Set the image view image
    imageView.image = self.image;
}

代码完成了这项工作,但是,当我从图像选择器推送到第二个视图控制器时,它会在转换时滞后。

理想情况下,我希望顺利过渡,但如果只是等了半秒钟或者其他东西然后顺利移动,我会很高兴。

可以解释为什么会发生这种情况以及如何/如果我可以绕过它?

感谢。

2 个答案:

答案 0 :(得分:3)

延迟可能来自渲染图像,你可以尝试让你的UploadViewController的初始视图包含一个活动微调器,然后在viewDidAppear方法中实际设置图像,这个方法应该在动画完成后调用。

答案 1 :(得分:0)

试试这个,这里引入计时器以提供延迟(0.5秒),

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{    
    [NSTimerscheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerAction:) userInfo:info repeats:NO];
}


-(void)timerAction:(NSTimer *)timer
{
  UploadViewController *uploadViewController = [[UploadViewController alloc] initWithNibName:@"UploadViewController" bundle:nil];
    [uploadViewController setImage:[[timer userInfo]objectForKey:@"UIImagePickerControllerOriginalImage"]];

    [picker pushViewController:uploadViewController animated:YES];
   [uploadViewController release];
}